diff --git a/.travis.yml b/.travis.yml index 7f00bca88..da3018138 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,8 @@ language: python cache: apt python: + - "2.6" - "2.7" -# - "3.3" dependent on ncclient 3.3 support -# - "pypy" before_install: - sudo apt-get install -qq python-dev libxml2-dev libxslt-dev @@ -17,12 +16,3 @@ script: nosetests -v --with-coverage --cover-package=jnpr.junos --cover-inclusiv notifications: email: false - -#deploy: - #provider: pypi # http://about.travis-ci.org/docs/user/deployment/pypi/ - #user: - #password: see http://about.travis-ci.org/docs/user/encryption-keys/ - #on: - #tags: true #only deploy to pypi when tags are updated -### -### possibly recommended for deployment: http://about.travis-ci.org/docs/user/travis-pro/ \ No newline at end of file diff --git a/lib/jnpr/junos/cfg/user_ssh_key.py b/lib/jnpr/junos/cfg/user_ssh_key.py index fd3a30948..7444b29af 100644 --- a/lib/jnpr/junos/cfg/user_ssh_key.py +++ b/lib/jnpr/junos/cfg/user_ssh_key.py @@ -98,4 +98,4 @@ def _r_list(self): def _r_catalog(self): # no catalog but the keys - self._rcatalog = {k: None for k in self.list} + self._rcatalog = dict((k, None) for k in self.list) diff --git a/lib/jnpr/junos/exception.py b/lib/jnpr/junos/exception.py index 688f70abd..85c7d7e69 100644 --- a/lib/jnpr/junos/exception.py +++ b/lib/jnpr/junos/exception.py @@ -1,6 +1,7 @@ from lxml import etree from jnpr.junos import jxml + class RpcError(Exception): """ Parent class for all junos-pyez RPC Exceptions @@ -22,6 +23,7 @@ def __repr__(self): if None != self.rsp: return etree.tostring(self.rsp, pretty_print=True) + class CommitError(RpcError): """ Generated in response to a commit-check or a commit action. @@ -43,13 +45,14 @@ def __init__(self, rsp): class UnlockError(RpcError): """ - Generated in response to attempting to unlock the + Generated in response to attempting to unlock the configuration database. """ def __init__(self, rsp): RpcError.__init__(self, rsp=rsp) self.rpc_error = jxml.rpc_error(rsp) + class PermissionError(RpcError): """ Generated in response to invoking an RPC for which the @@ -68,6 +71,7 @@ def __init__(self, cmd=None, rsp=None): #### ================================================================ #### ================================================================ + class ConnectError(Exception): """ Parent class for all connection related exceptions @@ -87,31 +91,34 @@ def host(self): def port(self): """ login SSH port """ return self.dev._port - + def __init__(self, dev): self.dev = dev # @@@ need to attach attributes for each access # @@@ to user-name, host, jump-host, etc. def __repr__(self): - return "{}({})".format( - self.__class__.__name__, - self.dev.hostname ) + return "{0}({1})".format( + self.__class__.__name__, + self.dev.hostname) __str__ = __repr__ + class ProbeError(ConnectError): """ Generated if auto_probe is enabled and the probe action fails """ pass - -class ConnectAuthError(ConnectError): + + +class ConnectAuthError(ConnectError): """ Generated if the user-name, password is invalid """ pass + class ConnectTimeoutError(ConnectError): """ Generated if the NETCONF session fails to connect, could @@ -120,12 +127,14 @@ class ConnectTimeoutError(ConnectError): """ pass + class ConnectUnknownHostError(ConnectError): """ Generated if the specific hostname does not DNS resolve """ pass + class ConnectRefusedError(ConnectError): """ Generated if the specified host denies the NETCONF; could @@ -134,10 +143,11 @@ class ConnectRefusedError(ConnectError): """ pass + class ConnectNotMasterError(ConnectError): """ Generated if the connection is made to a non-master routing-engine. This could be a backup RE on an MX device, or a virtual-chassis member (linecard), for example """ - pass \ No newline at end of file + pass diff --git a/lib/jnpr/junos/facts/swver.py b/lib/jnpr/junos/facts/swver.py index c8db07f49..5f0d9b416 100644 --- a/lib/jnpr/junos/facts/swver.py +++ b/lib/jnpr/junos/facts/swver.py @@ -107,7 +107,7 @@ def facts_software_version(junos, facts): # extract the version information out of the RPC response # ------------------------------------------------------------------------ - f_master = facts.get('master') + f_master = facts.get('master') if x_swver.tag == 'multi-routing-engine-results': # we need to find/identify each of the routing-engine (CPU) versions. @@ -115,7 +115,7 @@ def facts_software_version(junos, facts): facts['2RE'] = True versions = [] - xpath = './multi-routing-engine-item[re-name="{}"]/software-information/host-name'.format( + xpath = './multi-routing-engine-item[re-name="{0}"]/software-information/host-name'.format( f_master.lower()) facts['hostname'] = x_swver.findtext(xpath) if facts['hostname'] is None: diff --git a/lib/jnpr/junos/utils/fs.py b/lib/jnpr/junos/utils/fs.py index 07400bb42..f064e13b3 100644 --- a/lib/jnpr/junos/utils/fs.py +++ b/lib/jnpr/junos/utils/fs.py @@ -197,10 +197,7 @@ def ls(self, path='.', brief=False, followlink=True): if brief is True: results['files'] = [f.findtext('file-name').strip() for f in files] else: - results['files'] = { - f.findtext('file-name').strip(): FS._decode_file(f) - for f in files - } + results['files'] = dict((f.findtext('file-name').strip(), FS._decode_file(f)) for f in files) return results @@ -228,7 +225,7 @@ def _decode(fs): r['avail_block'] = int(ab.text) return r - return {_name(fs): _decode(fs) for fs in rsp.xpath('filesystem')} + return dict((_name(fs), _decode(fs)) for fs in rsp.xpath('filesystem')) # ------------------------------------------------------------------------- ### storage_cleanup_check, storage_cleanip @@ -245,7 +242,7 @@ def _decode(f): } # return a dict of name/decode pairs for each file - return {_name(f): _decode(f) for f in files} + return dict((_name(f), _decode(f)) for f in files) def storage_cleanup_check(self): """ diff --git a/lib/jnpr/junos/utils/sw.py b/lib/jnpr/junos/utils/sw.py index a6c04c09e..1446d8a17 100644 --- a/lib/jnpr/junos/utils/sw.py +++ b/lib/jnpr/junos/utils/sw.py @@ -361,7 +361,7 @@ def _progress(report): x).group(1) for x in self._RE_list] for vc_id in vc_members: _progress( - "installing software on VC member: {} ... please be" + "installing software on VC member: {0} ... please be" " patient ...".format(vc_id)) ok &= self.pkgadd(remote_package, member=vc_id) dev.timeout = restore_timeout diff --git a/tests/functional/test_core.py b/tests/functional/test_core.py index a7c498996..eb359ec65 100644 --- a/tests/functional/test_core.py +++ b/tests/functional/test_core.py @@ -34,7 +34,7 @@ def test_device_set_timeout(self): assert self.dev.timeout == 35 def test_device_cli(self): - self.assertIn('srx210', self.dev.cli('show version')) + self.assertTrue('srx210' in self.dev.cli('show version')) def test_device_rpc(self): sw = self.dev.rpc.get_software_information() diff --git a/tests/unit/facts/test_chassis.py b/tests/unit/facts/test_chassis.py index f2ce8e685..9ad7adc50 100644 --- a/tests/unit/facts/test_chassis.py +++ b/tests/unit/facts/test_chassis.py @@ -35,8 +35,7 @@ def test_2RE_true(self, mock_execute): def test_chassis_exception_ConnectNotMasterError(self): xmldata = etree.XML('test') self.dev.rpc.get_chassis_inventory = MagicMock(side_effect=xmldata) - with self.assertRaises(ConnectNotMasterError): - chassis(self.dev, self.facts) + self.assertRaises(ConnectNotMasterError, chassis, self.dev, self.facts) def _read_file(self, fname): from ncclient.xml_ import NCElement diff --git a/tests/unit/facts/test_domain.py b/tests/unit/facts/test_domain.py index fcdd77639..447c6e244 100644 --- a/tests/unit/facts/test_domain.py +++ b/tests/unit/facts/test_domain.py @@ -38,5 +38,5 @@ def test_resolv_conf_no_domain(self, mock_fs_cat): """ self.facts['hostname'] = 'test' facts_domain(self.dev, self.facts) - self.assertIsNone(self.facts['domain']) + self.assertEqual(self.facts['domain'], None) self.assertEqual(self.facts['fqdn'], 'test') diff --git a/tests/unit/facts/test_srx_cluster.py b/tests/unit/facts/test_srx_cluster.py index 7c4382fd6..825fc7832 100644 --- a/tests/unit/facts/test_srx_cluster.py +++ b/tests/unit/facts/test_srx_cluster.py @@ -34,7 +34,7 @@ def test_srx_cluster(self, mock_execute): def test_srx_cluster_none(self): self.facts['personality'] = 'MX' - self.assertIsNone(srx_cluster(self.dev, self.facts)) + self.assertEqual(srx_cluster(self.dev, self.facts), None) @patch('jnpr.junos.Device.execute') def test_srx_cluster_no_node(self, mock_execute): diff --git a/tests/unit/facts/test_swver.py b/tests/unit/facts/test_swver.py index 4c0a906b2..885dde797 100644 --- a/tests/unit/facts/test_swver.py +++ b/tests/unit/facts/test_swver.py @@ -16,7 +16,7 @@ class TestVersionInfo(unittest.TestCase): def test_version_info_after_type_len_else(self): - self.assertIsNone(version_info('12.1X46-D10').build) + self.assertEqual(version_info('12.1X46-D10').build, None) def test_version_info_constructor_else_exception(self): self.assertEqual(version_info('11.4R7').build, '7') @@ -27,16 +27,16 @@ def test_version_info_repr(self): 'type=R, minor=7, build=5)') def test_version_info_lt(self): - self.assertLess(version_info('13.3-20131120'), (14, 1)) + self.assertTrue(version_info('13.3-20131120') < (14, 1)) def test_version_info_lt_eq(self): - self.assertLessEqual(version_info('13.3-20131120'), (14, 1)) + self.assertTrue(version_info('13.3-20131120') <= (14, 1)) def test_version_info_gt(self): - self.assertGreater(version_info('13.3-20131120'), (12, 1)) + self.assertTrue(version_info('13.3-20131120') > (12, 1)) def test_version_info_gt_eq(self): - self.assertGreaterEqual(version_info('13.3-20131120'), (12, 1)) + self.assertTrue(version_info('13.3-20131120') >= (12, 1)) def test_version_info_eq(self): self.assertEqual(version_info('13.3-20131120'), (13, 3)) diff --git a/tests/unit/test_device.py b/tests/unit/test_device.py index 7837474ba..a7a86cfcb 100644 --- a/tests/unit/test_device.py +++ b/tests/unit/test_device.py @@ -71,14 +71,12 @@ def tearDown(self, mock_session): @patch('jnpr.junos.device.netconf_ssh') def test_device_ConnectAuthError(self, mock_manager): mock_manager.connect.side_effect = NcErrors.AuthenticationError - with self.assertRaises(EzErrors.ConnectAuthError): - self.dev.open() + self.assertRaises(EzErrors.ConnectAuthError, self.dev.open) @patch('jnpr.junos.device.netconf_ssh') def test_device_ConnectRefusedError(self, mock_manager): mock_manager.connect.side_effect = NcErrors.SSHError - with self.assertRaises(EzErrors.ConnectRefusedError): - self.dev.open() + self.assertRaises(EzErrors.ConnectRefusedError, self.dev.open) @patch('jnpr.junos.device.netconf_ssh') @patch('jnpr.junos.device.datetime') @@ -89,8 +87,7 @@ def test_device_ConnectTimeoutError(self, mock_datetime, mock_manager): currenttime = datetime.now() mock_datetime.datetime.now.side_effect = [currenttime, currenttime + timedelta(minutes=4)] - with self.assertRaises(EzErrors.ConnectTimeoutError): - self.dev.open() + self.assertRaises(EzErrors.ConnectTimeoutError, self.dev.open) @patch('jnpr.junos.device.netconf_ssh') @patch('jnpr.junos.device.datetime') @@ -101,21 +98,18 @@ def test_device_diff_err_message(self, mock_datetime, mock_manager): currenttime = datetime.now() mock_datetime.datetime.now.side_effect = [currenttime, currenttime + timedelta(minutes=4)] - with self.assertRaises(EzErrors.ConnectError): - self.dev.open() + self.assertRaises(EzErrors.ConnectError, self.dev.open) @patch('jnpr.junos.device.netconf_ssh') def test_device_ConnectUnknownHostError(self, mock_manager): import socket mock_manager.connect.side_effect = socket.gaierror - with self.assertRaises(EzErrors.ConnectUnknownHostError): - self.dev.open() + self.assertRaises(EzErrors.ConnectUnknownHostError, self.dev.open) @patch('jnpr.junos.device.netconf_ssh') def test_device_other_error(self, mock_manager): mock_manager.connect.side_effect = TypeError - with self.assertRaises(EzErrors.ConnectError): - self.dev.open() + self.assertRaises(EzErrors.ConnectError, self.dev.open) def test_device_property_logfile_isinstance(self): mock = MagicMock() @@ -158,23 +152,23 @@ def test_device__sshconf_lkup(self, os_mock, open_mock, mock_paramiko): @patch('os.getenv') def test_device__sshconf_lkup_path_not_exists(self, mock_env): mock_env.return_value = '/home/test' - self.assertIsNone(self.dev._sshconf_lkup()) + self.assertEqual(self.dev._sshconf_lkup(), None) @patch('os.getenv') def test_device__sshconf_lkup_home_not_defined(self, mock_env): mock_env.return_value = None - self.assertIsNone(self.dev._sshconf_lkup()) + self.assertEqual(self.dev._sshconf_lkup(), None) mock_env.assert_called_with('HOME') @patch('ncclient.manager.connect') @patch('jnpr.junos.Device.execute') def test_device_open(self, mock_connect, mock_execute): - with patch('jnpr.junos.utils.fs.FS.cat') as mock_cat: + with patch('jnpr.junos.utils.fs.FS.cat') as mock_cat: mock_cat.return_value = """ domain jls.net - """ + """ mock_connect.side_effect = self._mock_manager mock_execute.side_effect = self._mock_manager self.dev2 = Device(host='2.2.2.2', user='rick', password='password123') @@ -182,14 +176,14 @@ def test_device_open(self, mock_connect, mock_execute): self.assertEqual(self.dev2.connected, True) @patch('jnpr.junos.Device.execute') - def test_device_facts(self, mock_execute): + def test_device_facts(self, mock_execute): with patch('jnpr.junos.utils.fs.FS.cat') as mock_cat: mock_execute.side_effect = self._mock_manager mock_cat.return_value = """ domain jls.net - """ + """ self.dev.facts_refresh() assert self.dev.facts['version'] == facts['version'] @@ -200,7 +194,7 @@ def test_device_user(self): self.assertEqual(self.dev.user, 'rick') def test_device_get_password(self): - self.assertIsNone(self.dev.password) + self.assertEqual(self.dev.password, None) def test_device_set_password(self): self.dev.password = 'secret' @@ -231,12 +225,12 @@ def test_device_cli(self, mock_execute): @patch('jnpr.junos.Device.execute') def test_device_cli_conf_info(self, mock_execute): mock_execute.side_effect = self._mock_manager - self.assertIn('ge-0/0/0', self.dev.cli('show configuration')) + self.assertTrue('ge-0/0/0' in self.dev.cli('show configuration')) @patch('jnpr.junos.Device.execute') def test_device_cli_output(self, mock_execute): mock_execute.side_effect = self._mock_manager - self.assertIn('Alarm', self.dev.cli('show system alarms')) + self.assertTrue('Alarm' in self.dev.cli('show system alarms')) @patch('jnpr.junos.Device.execute') def test_device_cli_rpc(self, mock_execute): @@ -324,22 +318,24 @@ def test_device_bind_kvarg(self): self.assertEqual(self.dev.kw, 'Test') def test_device_bind_varg_exception(self): - with self.assertRaises(ValueError): + def varg(): self.dev.bind() mock = MagicMock() mock.__name__ = 'magic mock' #for *args self.dev.bind(mock) self.dev.bind(mock) + self.assertRaises(ValueError, varg) def test_device_bind_kvarg_exception(self): - with self.assertRaises(ValueError): + def kve(): self.dev.bind() mock = MagicMock() mock.__name__ = 'magic mock' #for **kwargs self.dev.bind(kw=mock) self.dev.bind(kw=mock) + self.assertRaises(ValueError, kve) def test_device_template(self): # Try to load the template relative to module base diff --git a/tests/unit/test_jxml.py b/tests/unit/test_jxml.py index 47d496e30..1a4c73889 100644 --- a/tests/unit/test_jxml.py +++ b/tests/unit/test_jxml.py @@ -32,4 +32,4 @@ def test_remove_namespaces(self): i = elem.tag.find('}') if i > 0: i = i + 1 - self.assertLessEqual(i, 0) + self.assertTrue(i <= 0) diff --git a/tests/unit/test_rpcmeta.py b/tests/unit/test_rpcmeta.py index c7a105479..95034c4af 100644 --- a/tests/unit/test_rpcmeta.py +++ b/tests/unit/test_rpcmeta.py @@ -19,7 +19,7 @@ def setUp(self): self.rpc = _RpcMetaExec(self.dev) def test_rpcmeta_constructor(self): - self.assertIsInstance(self.rpc._junos, Device) + self.assertTrue(isinstance(self.rpc._junos, Device)) @patch('jnpr.junos.device.Device.execute') def test_rpcmeta_load_config(self, mock_execute_fn): diff --git a/tests/unit/utils/test_config.py b/tests/unit/utils/test_config.py index f222cbc9b..eb983249d 100644 --- a/tests/unit/utils/test_config.py +++ b/tests/unit/utils/test_config.py @@ -19,7 +19,7 @@ def setUp(self): self.conf = Config(self.dev) def test_config_constructor(self): - self.assertIsInstance(self.conf._dev, Device) + self.assertTrue(isinstance(self.conf._dev, Device)) def test_config_confirm(self): self.conf.rpc.commit_configuration = MagicMock() @@ -38,12 +38,11 @@ def test_config_commit_comment(self): @patch('jnpr.junos.utils.config.JXML.remove_namespaces') def test_config_commit_exception(self, mock_jxml): - with self.assertRaises(AttributeError): - class MyException(Exception): - xml = 'test' - self.conf.rpc.commit_configuration = \ - MagicMock(side_effect=MyException) - self.conf.commit() + class MyException(Exception): + xml = 'test' + self.conf.rpc.commit_configuration = \ + MagicMock(side_effect=MyException) + self.assertRaises(AttributeError, self.conf.commit) def test_config_commit_exception_RpcError(self): ex = RpcError(rsp='ok') @@ -58,8 +57,7 @@ def test_config_commit_exception_RpcError(self): el = root.find('company') ex = RpcError(rsp=el) self.conf.rpc.commit_configuration = MagicMock(side_effect=ex) - with self.assertRaises(CommitError): - self.conf.commit() + self.assertRaises(CommitError, self.conf.commit) def test_commit_check(self): self.conf.rpc.commit_configuration = MagicMock() @@ -86,8 +84,7 @@ def test_config_commit_check_exception_RpcError(self): el = root.find('company') ex = RpcError(rsp=el) self.conf.rpc.commit_configuration = MagicMock(side_effect=ex) - with self.assertRaises(CommitError): - self.conf.commit_check() + self.assertRaises(CommitError, self.conf.commit_check) def test_config_diff(self): self.conf.rpc.get_configuration = MagicMock() diff --git a/tests/unit/utils/test_fs.py b/tests/unit/utils/test_fs.py index 520a5d1f5..db924f8e1 100644 --- a/tests/unit/utils/test_fs.py +++ b/tests/unit/utils/test_fs.py @@ -27,12 +27,12 @@ def setUp(self, mock_connect): def test_cat_wrong_path_return_none(self): path = 'test/report' - self.assertIsNone(self.fs.cat(path)) + 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.assertIn('testing cat functionality', self.fs.cat(path)) + 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): @@ -50,7 +50,7 @@ def test_pwd(self, mock_execute): def test_checksum_return_none(self): path = 'test/report' - self.assertIsNone(self.fs.checksum(path)) + self.assertEqual(self.fs.checksum(path), None) def test_checksum_unknown_calc(self): path = 'test/report' @@ -68,7 +68,7 @@ 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.assertDictEqual(self.fs.stat(path), + self.assertEqual(self.fs.stat(path), {'owner': 'pqr', 'path': '/var/abc.sh', 'permissions': 755, 'permissions_text': '-rwxr-xr-x', 'size': 2, @@ -80,7 +80,7 @@ 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.assertDictEqual(self.fs.stat(path), + self.assertEqual(self.fs.stat(path), {'path': '/var', 'type': 'dir', 'file_count': 1, 'size': 2}) @@ -88,13 +88,13 @@ 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.assertIsNone(self.fs.stat(path)) + 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.assertDictEqual(self.fs.ls(path), + self.assertEqual(self.fs.ls(path), {'owner': 'pqr', 'path': '/var/abc.sh', 'permissions': 755, 'permissions_text': '-rwxr-xr-x', 'size': 2, @@ -106,7 +106,7 @@ 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.assertDictEqual(self.fs.ls(path), + self.assertEqual(self.fs.ls(path), {'files': {'abc': {'permissions_text': 'drwxr-xr-x', 'ts_date': 'Feb 17 15:30', @@ -122,7 +122,7 @@ def test_ls_return_none(self): path = 'test/abc' self.fs.dev.rpc.file_list = MagicMock() self.fs.dev.rpc.file_list.find.return_value = 'output' - self.assertIsNone(self.fs.ls(path)) + self.assertEqual(self.fs.ls(path), None) @patch('jnpr.junos.utils.fs.FS._decode_file') def test_ls_link_path_false(self, mock_decode_file): @@ -137,7 +137,7 @@ def test_ls_brief_true(self): path = 'test/stat/decode_dir' self.fs.dev.rpc.file_list = \ MagicMock(side_effect=self._mock_manager) - self.assertDictEqual(self.fs.ls(path, brief=True), + self.assertEqual(self.fs.ls(path, brief=True), {'files': ['abc'], 'path': '/var', 'type': 'dir', 'file_count': 1, 'size': 2}) @@ -145,7 +145,7 @@ def test_ls_calling___decode_dir_type_symbolic_link(self): path = 'test/stat/decode_symbolic_link' self.fs.dev.rpc.file_list = \ MagicMock(side_effect=self._mock_manager) - self.assertDictEqual(self.fs.ls(path), + self.assertEqual(self.fs.ls(path), {'files': {'abc': {'permissions_text': 'drwxr-xr-x', 'ts_date': 'Feb 17 15:30', @@ -221,7 +221,7 @@ def test_tgz_return_error(self, mock_execute): mock_execute.side_effect = self._mock_manager src = 'test/tgz.txt' dst = 'test/xyz' - self.assertIn('testing tgz', self.fs.tgz(src, dst)) + self.assertTrue('testing tgz' in self.fs.tgz(src, dst)) @patch('jnpr.junos.utils.fs.StartShell') def test_rmdir(self, mock_StartShell): @@ -257,7 +257,7 @@ def test_symlink(self, mock_StartShell): @patch('jnpr.junos.Device.execute') def test_storage_usage(self, mock_execute): mock_execute.side_effect = self._mock_manager - self.assertDictEqual(self.fs.storage_usage(), + self.assertEqual(self.fs.storage_usage(), {'/dev/abc': {'avail_block': 234234, 'used_blocks': 2346455, 'used_pct': '1', @@ -268,14 +268,14 @@ def test_storage_usage(self, mock_execute): @patch('jnpr.junos.Device.execute') def test_storage_cleanup(self, mock_execute): mock_execute.side_effect = self._mock_manager - self.assertDictEqual(self.fs.storage_cleanup(), + self.assertEqual(self.fs.storage_cleanup(), {'/var/abc.txt': {'ts_date': 'Apr 25 10:38', 'size': 11}}) @patch('jnpr.junos.Device.execute') def test_storage_cleanup_check(self, mock_execute): mock_execute.side_effect = self._mock_manager - self.assertDictEqual(self.fs.storage_cleanup_check(), + self.assertEqual(self.fs.storage_cleanup_check(), {'/var/abc.txt': {'ts_date': 'Apr 25 10:38', 'size': 11}}) diff --git a/tests/unit/utils/test_scp.py b/tests/unit/utils/test_scp.py index b1eac98c9..c468a5b32 100644 --- a/tests/unit/utils/test_scp.py +++ b/tests/unit/utils/test_scp.py @@ -25,7 +25,7 @@ def test_scp_open(self, mock_connect): def test_scp_close(self, mock_connect): self.dev.bind(scp=SCP) self.dev.scp.open() - self.assertIsNone(self.dev.scp.close()) + self.assertEqual(self.dev.scp.close(), None) @patch('paramiko.SSHClient') def test_scp_context(self, mock_connect): diff --git a/tests/unit/utils/test_start_shell.py b/tests/unit/utils/test_start_shell.py index fb1087da2..c8917a5b2 100644 --- a/tests/unit/utils/test_start_shell.py +++ b/tests/unit/utils/test_start_shell.py @@ -34,14 +34,13 @@ def test_startshell_close(self, mock_connect): def test_startshell_run(self, mock_wait): self.shell._chan = MagicMock() self.shell.run('ls') - self.assertIn(call.send('echo $?'), self.shell._chan.mock_calls) + self.assertTrue(call.send('echo $?') in self.shell._chan.mock_calls) @patch('jnpr.junos.utils.start_shell.select') def test_startshell_wait_for(self, mock_select): mock_select.return_value = ['> ', 2, 3] self.shell._chan = MagicMock() - self.assertIn(call.endswith('> '), - self.shell.wait_for('> ')[0].mock_calls) + self.assertTrue(call.endswith('> ') in self.shell.wait_for('> ')[0].mock_calls) @patch('jnpr.junos.utils.start_shell.StartShell.open') @patch('jnpr.junos.utils.start_shell.StartShell.close') diff --git a/tests/unit/utils/test_sw.py b/tests/unit/utils/test_sw.py index 4525d4506..b64f4e1a2 100644 --- a/tests/unit/utils/test_sw.py +++ b/tests/unit/utils/test_sw.py @@ -112,8 +112,7 @@ def test_sw_put(self, mock_scp_put, mock_scp): #mock_scp_put.side_effect = self.mock_put package = 'test.tgz' self.sw.put(package) - self.assertIn(call('test.tgz', '/var/tmp'), - mock_scp_put.mock_calls) + self.assertTrue(call('test.tgz', '/var/tmp') in mock_scp_put.mock_calls) @patch('jnpr.junos.utils.scp.SCP.__exit__') @patch('jnpr.junos.utils.scp.SCP.__init__') @@ -216,14 +215,14 @@ def test_sw_rollback(self, mock_execute): def test_sw_inventory(self): self.sw.dev.rpc.file_list = \ MagicMock(side_effect=self._mock_manager) - self.assertDictEqual(self.sw.inventory, + self.assertEqual(self.sw.inventory, {'current': None, 'rollback': None}) @patch('jnpr.junos.Device.execute') def test_sw_reboot(self, mock_execute): mock_execute.side_effect = self._mock_manager self.sw._multi_MX = True - self.assertIn('Shutdown NOW', self.sw.reboot()) + self.assertTrue('Shutdown NOW' in self.sw.reboot()) @patch('jnpr.junos.Device.execute') def test_sw_reboot_exception(self, mock_execute): @@ -235,7 +234,7 @@ def test_sw_reboot_exception(self, mock_execute): def test_sw_poweroff(self, mock_execute): mock_execute.side_effect = self._mock_manager self.sw._multi_MX = True - self.assertIn('Shutdown NOW', self.sw.poweroff()) + self.assertTrue('Shutdown NOW' in self.sw.poweroff()) @patch('jnpr.junos.Device.execute') def test_sw_poweroff_exception(self, mock_execute): diff --git a/tests/unit/utils/test_util.py b/tests/unit/utils/test_util.py index 5c6413833..4271f2739 100644 --- a/tests/unit/utils/test_util.py +++ b/tests/unit/utils/test_util.py @@ -24,9 +24,11 @@ def test_repr(self): self.assertEqual(repr(self.util), 'jnpr.junos.utils.Util(1.1.1.1)') def test_dev_setter_exception(self): - with self.assertRaises(RuntimeError): + def mod_dev(): self.util.dev = 'abc' + self.assertRaises(RuntimeError, mod_dev) def test_rpc_setter_exception(self): - with self.assertRaises(RuntimeError): + def mod_rpc(): self.util.rpc = 'abc' + self.assertRaises(RuntimeError, mod_rpc)