本文整理汇总了Python中jnpr.junos.utils.fs.FS.cwd方法的典型用法代码示例。如果您正苦于以下问题:Python FS.cwd方法的具体用法?Python FS.cwd怎么用?Python FS.cwd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jnpr.junos.utils.fs.FS
的用法示例。
在下文中一共展示了FS.cwd方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFS
# 需要导入模块: from jnpr.junos.utils.fs import FS [as 别名]
# 或者: from jnpr.junos.utils.fs.FS import cwd [as 别名]
class TestFS(unittest.TestCase):
@patch("ncclient.manager.connect")
def setUp(self, mock_connect):
mock_connect.side_effect = self._mock_manager
self.dev = Device(host="1.1.1.1", user="rick", password="password123", gather_facts=False)
self.dev.open()
self.fs = FS(self.dev)
def test_cat_wrong_path_return_none(self):
path = "test/report"
self.assertEqual(self.fs.cat(path), None)
def test_cat(self):
self.fs._dev.rpc.file_show = MagicMock(side_effect=self._mock_manager)
path = "test/cat.txt"
self.assertTrue("testing cat functionality" in self.fs.cat(path))
self.fs._dev.rpc.file_show.assert_called_with(filename="test/cat.txt")
def test_cwd(self):
self.fs._dev.rpc.set_cli_working_directory = MagicMock(side_effect=self._mock_manager)
folder = "change/directory"
self.assertEqual("change/directory", self.fs.cwd(folder))
self.fs._dev.rpc.set_cli_working_directory.assert_called_with(directory="change/directory")
@patch("jnpr.junos.Device.execute")
def test_pwd(self, mock_execute):
mock_execute.side_effect = MagicMock(side_effect=self._mock_manager)
self.fs.pwd()
self.assertEqual(self.fs.pwd(), "/cf/var/home/rick")
def test_checksum_return_none(self):
path = "test/report"
self.assertEqual(self.fs.checksum(path), None)
def test_checksum_unknown_calc(self):
path = "test/report"
self.assertRaises(ValueError, self.fs.checksum, path=path, calc="abc")
def test_checksum_return_rsp(self):
self.fs.dev.rpc.get_sha256_checksum_information = MagicMock(side_effect=self._mock_manager)
path = "test/checksum"
self.assertEqual(self.fs.checksum(path, "sha256"), "xxxx")
self.fs.dev.rpc.get_sha256_checksum_information.assert_called_with(path="test/checksum")
def test_stat_calling___decode_file(self):
path = "test/stat/decode_file"
self.fs.dev.rpc.file_list = MagicMock(side_effect=self._mock_manager)
self.assertEqual(
self.fs.stat(path),
{
"owner": "pqr",
"path": "/var/abc.sh",
"permissions": 755,
"permissions_text": "-rwxr-xr-x",
"size": 2,
"ts_date": "Mar 13 06:54",
"ts_epoc": "1394693680",
"type": "file",
},
)
def test_stat_calling___decode_dir(self):
path = "test/stat/decode_dir"
self.fs.dev.rpc.file_list = MagicMock(side_effect=self._mock_manager)
self.assertEqual(self.fs.stat(path), {"path": "/var", "type": "dir", "file_count": 1, "size": 2})
def test_stat_return_none(self):
path = "test/abc"
self.fs.dev.rpc.file_list = MagicMock()
self.fs.dev.rpc.file_list.find.return_value = "output"
self.assertEqual(self.fs.stat(path), None)
def test_ls_calling___decode_file(self):
path = "test/stat/decode_file"
self.fs.dev.rpc.file_list = MagicMock(side_effect=self._mock_manager)
self.assertEqual(
self.fs.ls(path),
{
"owner": "pqr",
"path": "/var/abc.sh",
"permissions": 755,
"permissions_text": "-rwxr-xr-x",
"size": 2,
"ts_date": "Mar 13 06:54",
"ts_epoc": "1394693680",
"type": "file",
},
)
def test_ls_calling___decode_dir(self):
path = "test/stat/decode_dir"
self.fs.dev.rpc.file_list = MagicMock(side_effect=self._mock_manager)
self.assertEqual(
self.fs.ls(path),
{
"files": {
"abc": {
"permissions_text": "drwxr-xr-x",
"ts_date": "Feb 17 15:30",
"ts_epoc": "1392651039",
#.........这里部分代码省略.........
示例2: TestFS
# 需要导入模块: from jnpr.junos.utils.fs import FS [as 别名]
# 或者: from jnpr.junos.utils.fs.FS import cwd [as 别名]
class TestFS(unittest.TestCase):
@patch('ncclient.manager.connect')
def setUp(self, mock_connect):
mock_connect.side_effect = self._mock_manager
self.dev = Device(host='1.1.1.1', user='rick', password='password123',
gather_facts=False)
self.dev.open()
self.fs = FS(self.dev)
@patch('jnpr.junos.device.warnings')
def test_cat_wrong_path_return_none(self, mock_warnings):
path = 'test/report'
self.assertEqual(self.fs.cat(path), None)
def test_cat(self):
self.fs._dev.rpc.file_show = MagicMock(side_effect=self._mock_manager)
path = 'test/cat.txt'
self.assertTrue('testing cat functionality' in self.fs.cat(path))
self.fs._dev.rpc.file_show.assert_called_with(filename='test/cat.txt')
def test_cwd(self):
self.fs._dev.rpc.set_cli_working_directory = MagicMock(
side_effect=self._mock_manager)
folder = 'change/directory'
self.assertEqual('change/directory', self.fs.cwd(folder))
self.fs._dev.rpc.set_cli_working_directory.\
assert_called_with(directory='change/directory')
@patch('jnpr.junos.Device.execute')
def test_pwd(self, mock_execute):
mock_execute.side_effect = MagicMock(side_effect=self._mock_manager)
self.fs.pwd()
self.assertEqual(self.fs.pwd(), '/cf/var/home/rick')
@patch('jnpr.junos.device.warnings')
def test_checksum_return_none(self, mock_warnings):
path = 'test/report'
self.assertEqual(self.fs.checksum(path), None)
def test_checksum_unknown_calc(self):
path = 'test/report'
self.assertRaises(ValueError, self.fs.checksum, path=path, calc='abc')
def test_checksum_return_rsp(self):
self.fs.dev.rpc.get_sha256_checksum_information = \
MagicMock(side_effect=self._mock_manager)
path = 'test/checksum'
self.assertEqual(self.fs.checksum(path, 'sha256'), 'xxxx')
self.fs.dev.rpc.get_sha256_checksum_information.\
assert_called_with(path='test/checksum')
def test_stat_calling___decode_file(self):
path = 'test/stat/decode_file'
self.fs.dev.rpc.file_list = \
MagicMock(side_effect=self._mock_manager)
self.assertEqual(self.fs.stat(path),
{'owner': 'pqr', 'path': '/var/abc.sh',
'permissions': 755,
'permissions_text': '-rwxr-xr-x', 'size': 2,
'ts_date': 'Mar 13 06:54',
'ts_epoc': '1394693680',
'type': 'file'})
def test_stat_calling___decode_dir(self):
path = 'test/stat/decode_dir'
self.fs.dev.rpc.file_list = \
MagicMock(side_effect=self._mock_manager)
self.assertEqual(self.fs.stat(path),
{'path': '/var', 'type': 'dir', 'file_count': 1,
'size': 2})
def test_stat_return_none(self):
path = 'test/abc'
self.fs.dev.rpc.file_list = MagicMock()
self.fs.dev.rpc.file_list.find.return_value = 'output'
self.assertEqual(self.fs.stat(path), None)
def test_ls_calling___decode_file(self):
path = 'test/stat/decode_file'
self.fs.dev.rpc.file_list = \
MagicMock(side_effect=self._mock_manager)
self.assertEqual(self.fs.ls(path),
{'owner': 'pqr', 'path': '/var/abc.sh',
'permissions': 755,
'permissions_text': '-rwxr-xr-x', 'size': 2,
'ts_date': 'Mar 13 06:54',
'ts_epoc': '1394693680',
'type': 'file'})
def test_ls_calling___decode_dir(self):
path = 'test/stat/decode_dir'
self.fs.dev.rpc.file_list = \
MagicMock(side_effect=self._mock_manager)
self.assertEqual(self.fs.ls(path),
{'files':
{'abc': {'permissions_text': 'drwxr-xr-x',
'ts_date': 'Feb 17 15:30',
'ts_epoc': '1392651039',
'owner': 'root', 'path': 'abc',
#.........这里部分代码省略.........