From 1e22488c432f8fd7f880b19f6d5aa9693bd432ff Mon Sep 17 00:00:00 2001 From: Alex Murray Date: Wed, 31 Jan 2024 16:31:44 +1030 Subject: [PATCH 2/2] tests/unit: update to use assertEqual for python 3.12 As reported downstream to Ubuntu in LP: #2051540 Signed-off-by: Alex Murray --- tests/unit/test_applications.py | 12 +- tests/unit/test_backend.py | 16 +- tests/unit/test_backend_iptables.py | 88 ++++----- tests/unit/test_common.py | 278 ++++++++++++++-------------- tests/unit/test_parser.py | 22 +-- tests/unit/test_util.py | 54 +++--- 6 files changed, 235 insertions(+), 235 deletions(-) diff --git a/tests/unit/test_applications.py b/tests/unit/test_applications.py index 07467c0..996dea1 100644 --- a/tests/unit/test_applications.py +++ b/tests/unit/test_applications.py @@ -37,9 +37,9 @@ class ApplicationsTestCase(unittest.TestCase): pass self.assertTrue('WWW' in self.profiles.keys(), "Could not find 'WWW'") - self.assertEquals(self.profiles['WWW']['ports'], "80/tcp") - self.assertEquals(self.profiles['WWW']['title'], "Web Server") - self.assertEquals(self.profiles['WWW']['description'], "Web server") + self.assertEqual(self.profiles['WWW']['ports'], "80/tcp") + self.assertEqual(self.profiles['WWW']['title'], "Web Server") + self.assertEqual(self.profiles['WWW']['description'], "Web server") def test_valid_profile_name(self): '''Test valid_profile_name()''' @@ -130,18 +130,18 @@ class ApplicationsTestCase(unittest.TestCase): def test_get_title(self): '''Test get_title()''' - self.assertEquals(ufw.applications.get_title(self.profiles['WWW']), + self.assertEqual(ufw.applications.get_title(self.profiles['WWW']), 'Web Server') def test_get_description(self): '''Test get_description()''' - self.assertEquals(ufw.applications.get_description(self.profiles['WWW']), + self.assertEqual(ufw.applications.get_description(self.profiles['WWW']), 'Web server') def test_get_ports(self): '''Test get_ports()''' expected_ports = ['80/tcp'] - self.assertEquals(ufw.applications.get_ports(self.profiles['WWW']), + self.assertEqual(ufw.applications.get_ports(self.profiles['WWW']), expected_ports) diff --git a/tests/unit/test_backend.py b/tests/unit/test_backend.py index cc57990..afe531c 100644 --- a/tests/unit/test_backend.py +++ b/tests/unit/test_backend.py @@ -35,18 +35,18 @@ class BackendTestCase(unittest.TestCase): def test_installation_defaults(self): '''Test installation defaults''' - self.assertEquals(self.backend.defaults['default_input_policy'], + self.assertEqual(self.backend.defaults['default_input_policy'], "drop") - self.assertEquals(self.backend.defaults['default_forward_policy'], + self.assertEqual(self.backend.defaults['default_forward_policy'], "drop") - self.assertEquals(self.backend.defaults['default_output_policy'], + self.assertEqual(self.backend.defaults['default_output_policy'], "accept") self.assertTrue("ipt_modules" not in self.backend.defaults) - self.assertEquals(self.backend.defaults['loglevel'], 'low') - self.assertEquals(self.backend.defaults['manage_builtins'], 'no') - self.assertEquals(self.backend.defaults['enabled'], 'no') - self.assertEquals(self.backend.defaults['ipv6'], 'yes') - self.assertEquals(self.backend.defaults['default_application_policy'], + self.assertEqual(self.backend.defaults['loglevel'], 'low') + self.assertEqual(self.backend.defaults['manage_builtins'], 'no') + self.assertEqual(self.backend.defaults['enabled'], 'no') + self.assertEqual(self.backend.defaults['ipv6'], 'yes') + self.assertEqual(self.backend.defaults['default_application_policy'], 'skip') diff --git a/tests/unit/test_backend_iptables.py b/tests/unit/test_backend_iptables.py index b2dfc8a..e958c95 100644 --- a/tests/unit/test_backend_iptables.py +++ b/tests/unit/test_backend_iptables.py @@ -129,42 +129,42 @@ class BackendIptablesTestCase(unittest.TestCase): '''Test get_app_rules_from_template()''' pr = ufw.frontend.parse_command(['rule', 'allow', 'CIFS']) rules = self.backend.get_app_rules_from_template(pr.data['rule']) - self.assertEquals(len(rules), 2) + self.assertEqual(len(rules), 2) for r in rules: - self.assertEquals(r.dapp, 'CIFS') + self.assertEqual(r.dapp, 'CIFS') pr = ufw.frontend.parse_command(['rule', 'deny', 'from', 'any', 'app', 'CIFS']) rules = self.backend.get_app_rules_from_template(pr.data['rule']) - self.assertEquals(len(rules), 2) + self.assertEqual(len(rules), 2) for r in rules: - self.assertEquals(r.sapp, 'CIFS') + self.assertEqual(r.sapp, 'CIFS') pr = ufw.frontend.parse_command(['rule', 'reject', 'to', 'any', 'app', 'CIFS', 'from', 'any', 'app', 'CIFS']) rules = self.backend.get_app_rules_from_template(pr.data['rule']) - self.assertEquals(len(rules), 2) + self.assertEqual(len(rules), 2) for r in rules: - self.assertEquals(r.dapp, 'CIFS') - self.assertEquals(r.sapp, 'CIFS') + self.assertEqual(r.dapp, 'CIFS') + self.assertEqual(r.sapp, 'CIFS') pr = ufw.frontend.parse_command(['rule', 'reject', 'to', 'any', 'app', 'WWW', 'from', 'any', 'app', 'WWW Secure']) rules = self.backend.get_app_rules_from_template(pr.data['rule']) - self.assertEquals(len(rules), 1) + self.assertEqual(len(rules), 1) for r in rules: - self.assertEquals(r.dapp, 'WWW') - self.assertEquals(r.sapp, 'WWW Secure') + self.assertEqual(r.dapp, 'WWW') + self.assertEqual(r.sapp, 'WWW Secure') pr = ufw.frontend.parse_command(['rule', 'allow', 'from', 'any', 'app', 'IPP', 'to', 'any', 'app', 'WWW']) rules = self.backend.get_app_rules_from_template(pr.data['rule']) - self.assertEquals(len(rules), 1) + self.assertEqual(len(rules), 1) for r in rules: - self.assertEquals(r.sapp, 'IPP') + self.assertEqual(r.sapp, 'IPP') pr = ufw.frontend.parse_command(['rule', 'allow', '12345']) tests.unit.support.check_for_exception(self, @@ -180,13 +180,13 @@ class BackendIptablesTestCase(unittest.TestCase): (s, res) = self.backend.update_app_rule('WWW') self.assertFalse(res) - self.assertEquals(s, "") + self.assertEqual(s, "") pr = ufw.frontend.parse_command([] + ['rule', 'allow', 'CIFS']) self.backend.rules.append(pr.data['rule']) (s, res) = self.backend.update_app_rule('WWW') self.assertFalse(res) - self.assertEquals(s, "") + self.assertEqual(s, "") (s, res) = self.backend.update_app_rule('CIFS') self.assertTrue(res) self.assertTrue('CIFS' in s) @@ -198,7 +198,7 @@ class BackendIptablesTestCase(unittest.TestCase): self.backend.rules6.append(pr.data['rule']) (s, res) = self.backend.update_app_rule('WWW') self.assertFalse(res) - self.assertEquals(s, "") + self.assertEqual(s, "") (s, res) = self.backend.update_app_rule('WWW Secure') self.assertTrue(res) self.assertTrue('WWW Secure' in s) @@ -212,7 +212,7 @@ class BackendIptablesTestCase(unittest.TestCase): self.backend.rules6.append(pr.data['rule']) (s, res) = self.backend.update_app_rule('WWW') self.assertFalse(res) - self.assertEquals(s, "") + self.assertEqual(s, "") (s, res) = self.backend.update_app_rule('WWW Full') self.assertTrue(res) self.assertTrue('WWW Full' in s) @@ -223,7 +223,7 @@ class BackendIptablesTestCase(unittest.TestCase): self.backend.rules6.append(pr.data['rule']) (s, res) = self.backend.update_app_rule('WWW') self.assertFalse(res) - self.assertEquals(s, "") + self.assertEqual(s, "") (s, res) = self.backend.update_app_rule('NFS') self.assertTrue(res) self.assertTrue('NFS' in s) @@ -231,10 +231,10 @@ class BackendIptablesTestCase(unittest.TestCase): def test_find_application_name(self): '''Test find_application_name()''' res = self.backend.find_application_name('WWW') - self.assertEquals(res, 'WWW') + self.assertEqual(res, 'WWW') res = self.backend.find_application_name('WwW') - self.assertEquals(res, 'WWW') + self.assertEqual(res, 'WWW') f = os.path.join(self.backend.files['apps'], "testapp") contents = ''' @@ -274,10 +274,10 @@ ports=80/tcp self.backend.rules6.append(pr.data['rule']) res = self.backend.find_other_position(2, v6=True) - self.assertEquals(res, 0) + self.assertEqual(res, 0) res = self.backend.find_other_position(1, v6=False) - self.assertEquals(res, 2) + self.assertEqual(res, 2) tests.unit.support.check_for_exception(self, ValueError, @@ -309,7 +309,7 @@ ports=80/tcp self.backend.rules6.append(pr.data['rule']) res = self.backend.find_other_position(3, v6=True) - self.assertEquals(res, 0) + self.assertEqual(res, 0) def test_get_loglevel(self): '''Test get_loglevel()''' @@ -339,7 +339,7 @@ ports=80/tcp def test_get_rules_count(self): '''Test get_rules_count()''' res = self.backend.get_rules_count(v6=False) - self.assertEquals(res, 0) + self.assertEqual(res, 0) pr = ufw.frontend.parse_command([] + ['rule', 'allow', 'from', '1234:fff::/64', @@ -355,10 +355,10 @@ ports=80/tcp self.backend.rules6.append(pr.data['rule']) res = self.backend.get_rules_count(v6=False) - self.assertEquals(res, 1) + self.assertEqual(res, 1) res = self.backend.get_rules_count(v6=True) - self.assertEquals(res, 2) + self.assertEqual(res, 2) def test_get_rule_by_number(self): '''Test get_rule_by_number()''' @@ -378,31 +378,31 @@ ports=80/tcp self.backend.rules6.append(pr3.data['rule']) res = self.backend.get_rule_by_number(1) - self.assertEquals(ufw.common.UFWRule.match(res, pr1.data['rule']), 0) - self.assertEquals(ufw.common.UFWRule.match(res, pr2.data['rule']), 1) - self.assertEquals(ufw.common.UFWRule.match(res, pr3.data['rule']), 1) + self.assertEqual(ufw.common.UFWRule.match(res, pr1.data['rule']), 0) + self.assertEqual(ufw.common.UFWRule.match(res, pr2.data['rule']), 1) + self.assertEqual(ufw.common.UFWRule.match(res, pr3.data['rule']), 1) res = self.backend.get_rule_by_number(2) - self.assertEquals(ufw.common.UFWRule.match(res, pr2.data['rule']), 0) - self.assertEquals(ufw.common.UFWRule.match(res, pr1.data['rule']), 1) - self.assertEquals(ufw.common.UFWRule.match(res, pr3.data['rule']), 1) + self.assertEqual(ufw.common.UFWRule.match(res, pr2.data['rule']), 0) + self.assertEqual(ufw.common.UFWRule.match(res, pr1.data['rule']), 1) + self.assertEqual(ufw.common.UFWRule.match(res, pr3.data['rule']), 1) res = self.backend.get_rule_by_number(3) - self.assertEquals(ufw.common.UFWRule.match(res, pr3.data['rule']), 0) - self.assertEquals(ufw.common.UFWRule.match(res, pr1.data['rule']), 1) - self.assertEquals(ufw.common.UFWRule.match(res, pr2.data['rule']), 1) + self.assertEqual(ufw.common.UFWRule.match(res, pr3.data['rule']), 0) + self.assertEqual(ufw.common.UFWRule.match(res, pr1.data['rule']), 1) + self.assertEqual(ufw.common.UFWRule.match(res, pr2.data['rule']), 1) res = self.backend.get_rule_by_number(4) - self.assertEquals(res, None) + self.assertEqual(res, None) pr4 = ufw.frontend.parse_command([] + ['rule', 'allow', 'CIFS']) self.backend.rules.append(pr4.data['rule']) pr4.data['rule'].set_v6(True) self.backend.rules6.append(pr4.data['rule']) res = self.backend.get_rule_by_number(6) - self.assertEquals(res, None) + self.assertEqual(res, None) res = self.backend.get_rule_by_number(4) - self.assertEquals(ufw.common.UFWRule.match(res, pr4.data['rule']), 1) + self.assertEqual(ufw.common.UFWRule.match(res, pr4.data['rule']), 1) def test_get_matching(self): '''Test get_matching()''' @@ -414,7 +414,7 @@ ports=80/tcp test_rule = pr1.data['rule'].dup_rule() res = self.backend.get_matching(test_rule) - self.assertEquals(len(res), 2) + self.assertEqual(len(res), 2) def test_set_bad_default_application_policy(self): '''Test bad set_default_application_policy()''' @@ -451,7 +451,7 @@ ports=80/tcp res = self.backend._get_default_policy("input") else: res = self.backend._get_default_policy("output") - self.assertEquals(res, policy) + self.assertEqual(res, policy) # no dryrun for routed self.backend.dryrun = False @@ -469,14 +469,14 @@ ports=80/tcp check_forward=True) if not forward_enabled: policy = "disabled" - self.assertEquals(res, policy) + self.assertEqual(res, policy) def test_set_default(self): '''Test set_default()''' self.backend.set_default(self.backend.files['defaults'], 'NEW_INPUT_POLICY', 'accept') - self.assertEquals(self.backend.defaults['new_input_policy'], 'accept') + self.assertEqual(self.backend.defaults['new_input_policy'], 'accept') def test_set_bad_default(self): '''Test bad set_default_policy()''' @@ -523,7 +523,7 @@ ports=80/tcp for cmd in cmds: pr = ufw.frontend.parse_command(cmd + []) action = cmd[1] - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) if 'rule' in pr.data: if pr.data['rule'].v6: @@ -576,7 +576,7 @@ ports=80/tcp for cmd in cmds: pr = ufw.frontend.parse_command(cmd + []) action = cmd[1] - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) if 'rule' in pr.data: if pr.data['rule'].v6: @@ -694,7 +694,7 @@ ports=80/tcp for cmd in cmds_sim: pr = ufw.frontend.parse_command(cmd + []) action = cmd[1] - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) if 'rule' in pr.data: self.ui.do_action(pr.action, pr.data['rule'], \ diff --git a/tests/unit/test_common.py b/tests/unit/test_common.py index 45e3e9d..37e52e0 100644 --- a/tests/unit/test_common.py +++ b/tests/unit/test_common.py @@ -78,7 +78,7 @@ class CommonTestCase(unittest.TestCase): try: raise ufw.common.UFWError("test") except ufw.common.UFWError as e: - self.assertEquals(e.value, "test", "'%s' != 'test'" % e.value) + self.assertEqual(e.value, "test", "'%s' != 'test'" % e.value) return self.assertTrue(False, "Did not raise an error") @@ -86,14 +86,14 @@ class CommonTestCase(unittest.TestCase): '''Test UFWError.str()''' e = ufw.common.UFWError("test") search = repr("test") - self.assertEquals(str(e), search, "'%s' != 'test'" % search) + self.assertEqual(str(e), search, "'%s' != 'test'" % search) def test__init_(self): '''Test UFWRule.__init__()''' r = ufw.common.UFWRule("allow", "tcp", "22") - self.assertEquals(r.action, "allow") - self.assertEquals(r.protocol, "tcp") - self.assertEquals(r.dport, "22") + self.assertEqual(r.action, "allow") + self.assertEqual(r.protocol, "tcp") + self.assertEqual(r.dport, "22") tests.unit.support.check_for_exception(self, ufw.common.UFWError, ufw.common.UFWRule, @@ -109,90 +109,90 @@ class CommonTestCase(unittest.TestCase): "interface_in=, interface_out=, logtype=, multi=False, " + \ "position=0, protocol=any, remove=False, sapp=, " + \ "sport=any, src=0.0.0.0/0, updated=False, v6=False" - self.assertEquals(res, search, "'%s' != '%s'" % (res, search)) + self.assertEqual(res, search, "'%s' != '%s'" % (res, search)) def test_dup_rule(self): '''Test dup_rule()''' r = self.rules["any"].dup_rule() - self.assertEquals(ufw.common.UFWRule.match(r, self.rules["any"]), 0) + self.assertEqual(ufw.common.UFWRule.match(r, self.rules["any"]), 0) def test_format_rule(self): '''Test format_rule()''' s = str(self.rules["any"]) - self.assertEquals(s, "-p all -j ACCEPT") + self.assertEqual(s, "-p all -j ACCEPT") s = str(self.rules["app-both"]) - self.assertEquals(s, "-p all --dport 80 --sport 80 -j DROP " + \ + self.assertEqual(s, "-p all --dport 80 --sport 80 -j DROP " + \ "-m comment --comment 'dapp_Apache,sapp_Apache'") s = str(self.rules["dapp"]) - self.assertEquals(s, "-p all --dport 80 -j ACCEPT " + \ + self.assertEqual(s, "-p all --dport 80 -j ACCEPT " + \ "-m comment --comment 'dapp_Apache'") s = str(self.rules["full-any"]) - self.assertEquals(s, "-p all -d 10.0.0.1 --dport 123 " + \ + self.assertEqual(s, "-p all -d 10.0.0.1 --dport 123 " + \ "-s 10.0.0.2 --sport 124 -j ACCEPT") s = str(self.rules["full-ipv6"]) - self.assertEquals(s, "-p ipv6 -d 10.0.0.1 --dport 123 " + \ + self.assertEqual(s, "-p ipv6 -d 10.0.0.1 --dport 123 " + \ "-s 10.0.0.2 --sport 124 -j DROP") s = str(self.rules["full-tcp"]) - self.assertEquals(s, "-p tcp -d 10.0.0.1 --dport 123 " + \ + self.assertEqual(s, "-p tcp -d 10.0.0.1 --dport 123 " + \ "-s 10.0.0.2 --sport 124 -j LIMIT") s = str(self.rules["full-udp"]) - self.assertEquals(s, "-p udp -d 10.0.0.1 --dport 123 " + \ + self.assertEqual(s, "-p udp -d 10.0.0.1 --dport 123 " + \ "-s 10.0.0.2 --sport 124 -j REJECT") s = str(self.rules["ipv6"]) - self.assertEquals(s, "-p ipv6 -j DROP") + self.assertEqual(s, "-p ipv6 -j DROP") s = str(self.rules["log"]) - self.assertEquals(s, "-p tcp --dport 22 -j ACCEPT_log") + self.assertEqual(s, "-p tcp --dport 22 -j ACCEPT_log") s = str(self.rules["log-all"]) - self.assertEquals(s, "-p tcp --dport 22 -j ACCEPT_log-all") + self.assertEqual(s, "-p tcp --dport 22 -j ACCEPT_log-all") r = self.rules["log-all"].dup_rule() r.set_action("deny_log-all") s = str(r) - self.assertEquals(s, "-p tcp --dport 22 -j DROP_log-all") + self.assertEqual(s, "-p tcp --dport 22 -j DROP_log-all") s = str(self.rules["multi-both"]) - self.assertEquals(s, "-p tcp -m multiport " + \ + self.assertEqual(s, "-p tcp -m multiport " + \ "--dports 80,443,8080:8090 " + \ "-m multiport --sports 23 -j ACCEPT") s = str(self.rules["multi-dport"]) - self.assertEquals(s, "-p tcp -m multiport " + \ + self.assertEqual(s, "-p tcp -m multiport " + \ "--dports 80,443,8080:8090 -j ACCEPT") s = str(self.rules["multi-sport"]) - self.assertEquals(s, "-p tcp -m multiport " + \ + self.assertEqual(s, "-p tcp -m multiport " + \ "--sports 80,443,8080:8090 -j ACCEPT") s = str(self.rules["reject-tcp"]) - self.assertEquals(s, "-p tcp -j REJECT --reject-with tcp-reset") + self.assertEqual(s, "-p tcp -j REJECT --reject-with tcp-reset") s = str(self.rules["reject-udp"]) - self.assertEquals(s, "-p udp -j REJECT") + self.assertEqual(s, "-p udp -j REJECT") s = str(self.rules["sapp"]) - self.assertEquals(s, "-p all --sport 80 -j DROP " + \ + self.assertEqual(s, "-p all --sport 80 -j DROP " + \ "-m comment --comment 'sapp_Apache'") s = str(self.rules["tcp"]) - self.assertEquals(s, "-p tcp -j LIMIT") + self.assertEqual(s, "-p tcp -j LIMIT") s = str(self.rules["udp"]) - self.assertEquals(s, "-p udp -j ACCEPT") + self.assertEqual(s, "-p udp -j ACCEPT") def test_set_action(self): '''Test set_action()''' r = self.rules["any"] for action in ['allow', 'deny', 'reject', 'limit']: r.set_action(action) - self.assertEquals(action, r.action, "%s != %s" % + self.assertEqual(action, r.action, "%s != %s" % (action, r.action)) def test_set_port(self): @@ -212,21 +212,21 @@ class CommonTestCase(unittest.TestCase): r = rule.dup_rule() r.set_port(port, loc) if loc == 'dst': - self.assertEquals(port, r.dport, "%s != %s" % (port, + self.assertEqual(port, r.dport, "%s != %s" % (port, r.dport)) else: - self.assertEquals(port, r.sport, "%s != %s" % (port, + self.assertEqual(port, r.sport, "%s != %s" % (port, r.sport)) r = self.rules["dapp"].dup_rule() r.dapp = "Apache" r.set_port("Apache", "dst") - self.assertEquals(r.dapp, r.dport, "%s != %s" % (r.dapp, r.dport)) + self.assertEqual(r.dapp, r.dport, "%s != %s" % (r.dapp, r.dport)) r = self.rules["sapp"].dup_rule() r.sapp = "Apache" r.set_port("Apache", "src") - self.assertEquals(r.sapp, r.sport, "%s != %s" % (r.sapp, r.sport)) + self.assertEqual(r.sapp, r.sport, "%s != %s" % (r.sapp, r.sport)) def test_set_port_bad(self): '''Test set_port() - bad''' @@ -263,7 +263,7 @@ class CommonTestCase(unittest.TestCase): r = self.rules["any"] for proto in ['any', 'tcp', 'udp', 'ipv6', 'esp', 'ah', 'vrrp']: r.set_protocol(proto) - self.assertEquals(proto, r.protocol, "%s != %s" % + self.assertEqual(proto, r.protocol, "%s != %s" % (proto, r.protocol)) def test_set_protocol_bad(self): @@ -281,20 +281,20 @@ class CommonTestCase(unittest.TestCase): x.set_v6(False) x._fix_anywhere() search = "0.0.0.0/0" - self.assertEquals(x.dst, search, "'%s' != '%s'" % (x.dst, search)) + self.assertEqual(x.dst, search, "'%s' != '%s'" % (x.dst, search)) y = x.dup_rule() y.set_v6(True) y._fix_anywhere() search = "::/0" - self.assertEquals(y.dst, search, "'%s' != '%s'" % (y.dst, search)) + self.assertEqual(y.dst, search, "'%s' != '%s'" % (y.dst, search)) def test_set_v6(self): '''Test set_v6()''' r = self.rules["any"] for ipv6 in [True, False]: r.set_v6(ipv6) - self.assertEquals(ipv6, r.v6, "%s != %s" % + self.assertEqual(ipv6, r.v6, "%s != %s" % (ipv6, r.v6)) def test_set_src(self): @@ -302,7 +302,7 @@ class CommonTestCase(unittest.TestCase): r = self.rules["any"] for src in ["10.0.0.3"]: r.set_src(src) - self.assertEquals(src, r.src, "%s != %s" % + self.assertEqual(src, r.src, "%s != %s" % (src, r.src)) def test_set_src_bad(self): @@ -319,7 +319,7 @@ class CommonTestCase(unittest.TestCase): r = self.rules["any"] for dst in ["10.0.0.3"]: r.set_dst(dst) - self.assertEquals(dst, r.dst, "%s != %s" % + self.assertEqual(dst, r.dst, "%s != %s" % (dst, r.dst)) def test_set_dst_bad(self): @@ -340,10 +340,10 @@ class CommonTestCase(unittest.TestCase): "=foo", "vethQNIAKF@if18", "lo"]: r.set_interface(if_type, interface) if if_type == "in": - self.assertEquals(interface, r.interface_in, "%s != %s" % + self.assertEqual(interface, r.interface_in, "%s != %s" % (interface, r.interface_in)) else: - self.assertEquals(interface, r.interface_out, "%s != %s" % + self.assertEqual(interface, r.interface_out, "%s != %s" % (interface, r.interface_out)) def test_set_interface_bad(self): @@ -370,7 +370,7 @@ class CommonTestCase(unittest.TestCase): '''Test set_position()''' r = self.rules["any"] r.set_position(2) - self.assertEquals(2, r.position) + self.assertEqual(2, r.position) def test_set_position_bad(self): '''Test set_position() - bad''' @@ -385,7 +385,7 @@ class CommonTestCase(unittest.TestCase): r = self.rules["any"] for logtype in ["", "log", "log-all"]: r.set_logtype(logtype) - self.assertEquals(logtype, r.logtype, "%s != %s" % + self.assertEqual(logtype, r.logtype, "%s != %s" % (logtype, r.logtype)) def test_set_logtype_bad(self): @@ -402,7 +402,7 @@ class CommonTestCase(unittest.TestCase): r = self.rules["any"] for direction in ["in", "out"]: r.set_direction(direction) - self.assertEquals(direction, r.direction, "%s != %s" % + self.assertEqual(direction, r.direction, "%s != %s" % (direction, r.direction)) def test_set_direction_bad(self): @@ -423,7 +423,7 @@ class CommonTestCase(unittest.TestCase): for rule in keys: r = self.rules[rule].dup_rule() r.normalize() - self.assertEquals(ufw.common.UFWRule.match(self.rules[rule], r), 0, + self.assertEqual(ufw.common.UFWRule.match(self.rules[rule], r), 0, "'%s' != '%s'" % (self.rules[rule], r)) # Bad rules @@ -452,109 +452,109 @@ class CommonTestCase(unittest.TestCase): rule = ufw.common.UFWRule("allow", "any", dst=addr) rule.set_v6(v6) rule.normalize() - self.assertEquals(expected, rule.dst, + self.assertEqual(expected, rule.dst, "'%s' != '%s'" % (expected, rule.dst)) - self.assertEquals(addr != expected, rule.updated, + self.assertEqual(addr != expected, rule.updated, "'%s' not updated" % addr) rule = ufw.common.UFWRule("allow", "any", src=addr) rule.set_v6(v6) rule.normalize() - self.assertEquals(expected, rule.src, + self.assertEqual(expected, rule.src, "'%s' != '%s'" % (expected, rule.src)) - self.assertEquals(addr != expected, rule.updated, + self.assertEqual(addr != expected, rule.updated, "'%s' not updated" % addr) def test_match(self): '''Test match()''' x = self.rules["full-any"].dup_rule() y = self.rules["full-any"].dup_rule() - self.assertEquals(ufw.common.UFWRule.match(x, y), 0) + self.assertEqual(ufw.common.UFWRule.match(x, y), 0) for action in ['reject', 'deny', 'limit']: y = self.rules["full-any"].dup_rule() y.set_action(action) - self.assertEquals(ufw.common.UFWRule.match(x, y), -1) + self.assertEqual(ufw.common.UFWRule.match(x, y), -1) for logtype in ['log', 'log-all']: y = self.rules["full-any"].dup_rule() y.set_logtype(logtype) - self.assertEquals(ufw.common.UFWRule.match(x, y), -1) + self.assertEqual(ufw.common.UFWRule.match(x, y), -1) for comment in ['comment1', 'comment2']: y = self.rules["full-any"].dup_rule() y.set_comment(comment) - self.assertEquals(ufw.common.UFWRule.match(x, y), -2) + self.assertEqual(ufw.common.UFWRule.match(x, y), -2) y = self.rules["full-any"].dup_rule() y.set_port("456", loc="dst") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = self.rules["full-any"].dup_rule() y.set_port("456", loc="src") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = self.rules["full-any"].dup_rule() y.set_protocol("tcp") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = self.rules["full-any"].dup_rule() y.set_src("192.168.0.1") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = self.rules["full-any"].dup_rule() y.set_dst("192.168.0.1") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = self.rules["full-any"].dup_rule() y.set_dst("fe80::1") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = ufw.common.UFWRule("allow", "tcp", dst="fe80::1") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = self.rules["full-any"].dup_rule() y.sapp = "OpenSSH" - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = self.rules["full-any"].dup_rule() y.dapp = "OpenSSH" - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) y = self.rules["full-any"].dup_rule() y.set_interface("in", "eth0") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) x = ufw.common.UFWRule("allow", "tcp", direction="out") y = x.dup_rule() y.set_interface("out", "eth0") - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) x = self.rules["any"].dup_rule() y = self.rules["any"].dup_rule() y.v6 = True - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) x = self.rules["any"].dup_rule() y = self.rules["any"].dup_rule() y.forward = True - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) x = self.rules["full-any"].dup_rule() y = self.rules["full-any"].dup_rule() y.forward = True - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) x = self.rules["multi-both"].dup_rule() y = self.rules["multi-both"].dup_rule() y.forward = True - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) x = ufw.common.UFWRule("allow", "tcp", direction="out") x.set_interface("out", "eth0") y = x.dup_rule() y.direction = "in" - self.assertEquals(ufw.common.UFWRule.match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.match(x, y), 1) tests.unit.support.check_for_exception(self, ValueError, x.match, @@ -564,108 +564,108 @@ class CommonTestCase(unittest.TestCase): '''Test fuzzy_dst_match()''' x = self.rules["full-any"].dup_rule() y = self.rules["full-any"].dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) x.set_protocol("tcp") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), -1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), -1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["multi-dport"].dup_rule() y = self.rules["multi-dport"].dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) y.set_protocol("any") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), -1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), -1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["multi-dport"].dup_rule() y = self.rules["multi-dport"].dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) y.set_protocol("any") y.set_port("%s,8181" % y.dport, "dst") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["any"].dup_rule() x.set_port("80") x.set_protocol("tcp") y = self.rules["multi-dport"].dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), -1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), -1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["any"].dup_rule() x.set_port("8081") x.set_protocol("tcp") y = self.rules["multi-dport"].dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), -1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), -1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["any"].dup_rule() x.set_port("8079") x.set_protocol("tcp") y = self.rules["multi-dport"].dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["full-any"].dup_rule() y = self.rules["full-any"].dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) y.set_direction("out") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) x = self.rules["full-any"].dup_rule() y = self.rules["full-any"].dup_rule() y.set_dst("10.0.0.3") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["full-any"].dup_rule() y = self.rules["full-any"].dup_rule() y.set_dst("11.0.0.0/8") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["full-any"].dup_rule() y = self.rules["full-any"].dup_rule() y.set_interface("in", "eth0") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), -1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), -1) x = self.rules["full-any"].dup_rule() x.set_interface("in", "eth0") y = x.dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 0) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 0) x = self.rules["full-any"].dup_rule() x.set_interface("in", "eth0") y = x.dup_rule() y.set_interface("in", "eth1") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["full-any"].dup_rule() x.set_interface("in", "lo") y = x.dup_rule() - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 0) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 0) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 0) x = self.rules["full-any"].dup_rule() x.set_interface("in", "lo") y = x.dup_rule() y.set_dst("11.0.0.0/8") - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["any"].dup_rule() y = x.dup_rule() y.set_v6(True) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) x = self.rules["any"].dup_rule() y = x.dup_rule() y.forward = True - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) - self.assertEquals(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(x, y), 1) + self.assertEqual(ufw.common.UFWRule.fuzzy_dst_match(y, x), 1) tests.unit.support.check_for_exception(self, ValueError, x.fuzzy_dst_match, @@ -685,60 +685,60 @@ class CommonTestCase(unittest.TestCase): '''Test get_app_tuple()''' r = self.rules['dapp'].dup_rule() t = r.get_app_tuple().split() - self.assertEquals(self.rules['dapp'].dapp, t[0]) - self.assertEquals(self.rules['dapp'].dst, t[1]) - self.assertEquals("any", t[2]) - self.assertEquals("0.0.0.0/0", t[3]) + self.assertEqual(self.rules['dapp'].dapp, t[0]) + self.assertEqual(self.rules['dapp'].dst, t[1]) + self.assertEqual("any", t[2]) + self.assertEqual("0.0.0.0/0", t[3]) r.set_direction("in") t = r.get_app_tuple().split() - self.assertEquals(self.rules['dapp'].dapp, t[0]) - self.assertEquals(self.rules['dapp'].dst, t[1]) - self.assertEquals("any", t[2]) - self.assertEquals("0.0.0.0/0", t[3]) - self.assertEquals("in", t[4]) + self.assertEqual(self.rules['dapp'].dapp, t[0]) + self.assertEqual(self.rules['dapp'].dst, t[1]) + self.assertEqual("any", t[2]) + self.assertEqual("0.0.0.0/0", t[3]) + self.assertEqual("in", t[4]) r.set_interface("in", "eth0") t = r.get_app_tuple().split() - self.assertEquals(self.rules['dapp'].dapp, t[0]) - self.assertEquals(self.rules['dapp'].dst, t[1]) - self.assertEquals("any", t[2]) - self.assertEquals("0.0.0.0/0", t[3]) - self.assertEquals("in_eth0", t[4]) + self.assertEqual(self.rules['dapp'].dapp, t[0]) + self.assertEqual(self.rules['dapp'].dst, t[1]) + self.assertEqual("any", t[2]) + self.assertEqual("0.0.0.0/0", t[3]) + self.assertEqual("in_eth0", t[4]) r = self.rules['sapp'].dup_rule() t = r.get_app_tuple().split() - self.assertEquals("any", t[0]) - self.assertEquals("0.0.0.0/0", t[1]) - self.assertEquals(self.rules['sapp'].sapp, t[2]) - self.assertEquals(self.rules['sapp'].src, t[3]) + self.assertEqual("any", t[0]) + self.assertEqual("0.0.0.0/0", t[1]) + self.assertEqual(self.rules['sapp'].sapp, t[2]) + self.assertEqual(self.rules['sapp'].src, t[3]) r.set_direction("out") t = r.get_app_tuple().split() - self.assertEquals("any", t[0]) - self.assertEquals("0.0.0.0/0", t[1]) - self.assertEquals(self.rules['sapp'].sapp, t[2]) - self.assertEquals(self.rules['sapp'].src, t[3]) - self.assertEquals("out", t[4]) + self.assertEqual("any", t[0]) + self.assertEqual("0.0.0.0/0", t[1]) + self.assertEqual(self.rules['sapp'].sapp, t[2]) + self.assertEqual(self.rules['sapp'].src, t[3]) + self.assertEqual("out", t[4]) r.set_interface("out", "eth0") t = r.get_app_tuple().split() - self.assertEquals("any", t[0]) - self.assertEquals("0.0.0.0/0", t[1]) - self.assertEquals(self.rules['sapp'].sapp, t[2]) - self.assertEquals(self.rules['sapp'].src, t[3]) - self.assertEquals("out_eth0", t[4]) + self.assertEqual("any", t[0]) + self.assertEqual("0.0.0.0/0", t[1]) + self.assertEqual(self.rules['sapp'].sapp, t[2]) + self.assertEqual(self.rules['sapp'].src, t[3]) + self.assertEqual("out_eth0", t[4]) # also test with '_' in the name (LP: #1098472) r = self.rules['sapp'].dup_rule() t = r.get_app_tuple().split() - self.assertEquals("any", t[0]) - self.assertEquals("0.0.0.0/0", t[1]) - self.assertEquals(self.rules['sapp'].sapp, t[2]) - self.assertEquals(self.rules['sapp'].src, t[3]) + self.assertEqual("any", t[0]) + self.assertEqual("0.0.0.0/0", t[1]) + self.assertEqual(self.rules['sapp'].sapp, t[2]) + self.assertEqual(self.rules['sapp'].src, t[3]) r.set_interface("out", "br_lan") t = r.get_app_tuple().split() - self.assertEquals("any", t[0]) - self.assertEquals("0.0.0.0/0", t[1]) - self.assertEquals(self.rules['sapp'].sapp, t[2]) - self.assertEquals(self.rules['sapp'].src, t[3]) - self.assertEquals("out_br_lan", t[4]) + self.assertEqual("any", t[0]) + self.assertEqual("0.0.0.0/0", t[1]) + self.assertEqual(self.rules['sapp'].sapp, t[2]) + self.assertEqual(self.rules['sapp'].src, t[3]) + self.assertEqual("out_br_lan", t[4]) def test_main(): # used by runner.py diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index 639238f..dd4a04c 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -85,7 +85,7 @@ class ParserTestCase(unittest.TestCase): '''Test UFWCommand.parse()''' c = ufw.parser.UFWCommand('basic', 'status') pr = c.parse(['status']) - self.assertEquals('status', pr.action, "%s != 'status'" % (pr.action)) + self.assertEqual('status', pr.action, "%s != 'status'" % (pr.action)) def test_ufwcommandbasic_parse_with_arg(self): '''Test UFWCommand.parse() - basic with arg''' @@ -372,7 +372,7 @@ class ParserTestCase(unittest.TestCase): #print("Result: rule %s" % res) - self.assertEquals(len(errors), 0, + self.assertEqual(len(errors), 0, "Rules did not match:\n%s\n(%d of %d)" % \ ("\n".join(errors), len(errors), count)) print("%d rules checked" % count) @@ -390,7 +390,7 @@ class ParserTestCase(unittest.TestCase): # TODO: more tests here by sending the cmd and the pr to a helper action = cmd[1] - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) del_cmd = cmd + [] @@ -402,7 +402,7 @@ class ParserTestCase(unittest.TestCase): # TODO: more tests here by sending the cmd and the pr to a helper action = del_cmd[2] - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) ins_cmd = cmd + [] ins_cmd.insert(1, 'insert') @@ -414,7 +414,7 @@ class ParserTestCase(unittest.TestCase): # TODO: more tests here by sending the cmd and the pr to a helper action = ins_cmd[3] - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) print("%d rules checked" % count) @@ -564,7 +564,7 @@ class ParserTestCase(unittest.TestCase): # TODO: more tests here by sending the cmd and the pr to a helper action = cmd[1] - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) print("%d rules checked" % count) @@ -655,7 +655,7 @@ class ParserTestCase(unittest.TestCase): action = 'update-with-new' elif action == 'default': action = "default-%s" % cmd[2] - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) def test_default_parse(self): @@ -691,7 +691,7 @@ class ParserTestCase(unittest.TestCase): if len(cmd) >= 3: pol = cmd[2] action = "default-%s-%s" % (cmd[1], pol) - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) def test_logging_parse(self): @@ -724,7 +724,7 @@ class ParserTestCase(unittest.TestCase): action = "logging-%s" % (cmd[1]) if cmd[1] != "on" and cmd[1] != "off": action = "logging-on_%s" % (cmd[1]) - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) def test_status_parse(self): @@ -753,7 +753,7 @@ class ParserTestCase(unittest.TestCase): action = cmd[0] if len(cmd) > 1: action = "%s-%s" % (cmd[0], cmd[1]) - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) def test_show_parse(self): @@ -785,7 +785,7 @@ class ParserTestCase(unittest.TestCase): # TODO: more tests here by sending the cmd and the pr to a # helper - self.assertEquals(action, pr.action, "%s != %s" % (action, \ + self.assertEqual(action, pr.action, "%s != %s" % (action, \ pr.action)) diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index ea206f7..ec14f1a 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -350,7 +350,7 @@ class UtilTestCase(unittest.TestCase): ] error_str = self._run_normalize_address(data) - self.assertEquals(error_str, "", error_str) + self.assertEqual(error_str, "", error_str) def test_normalize_address_netmask_to_cidr(self): '''Test normalize_address() with netmask_to_cidr''' @@ -390,7 +390,7 @@ class UtilTestCase(unittest.TestCase): ] error_str = self._run_normalize_address(data) - self.assertEquals(error_str, "", error_str) + self.assertEqual(error_str, "", error_str) def test_normalize_address_ipv6_cidr(self): '''Test normalize_address() with ipv6_cidr''' @@ -398,7 +398,7 @@ class UtilTestCase(unittest.TestCase): for cidr in range(0, 128): data.append((True, '::1/%d' % cidr, '::1/%d' % cidr)) error_str = self._run_normalize_address(data) - self.assertEquals(error_str, "", error_str) + self.assertEqual(error_str, "", error_str) def test_normalize_address_valid_netmask_to_non_cidr(self): '''Test normalize_address() with valid_netmask_to_non_cidr''' @@ -524,7 +524,7 @@ class UtilTestCase(unittest.TestCase): '192.0.0.0/%d.0.0.0' % i)) error_str = self._run_normalize_address(data) - self.assertEquals(error_str, "", error_str) + self.assertEqual(error_str, "", error_str) def test_normalize_address_ipv6_short_notation(self): '''Test normalize_address() with ipv6_short_notation''' @@ -535,7 +535,7 @@ class UtilTestCase(unittest.TestCase): '2001:db8:85a3:8d3:1319:8a2e:370:734'), ] error_str = self._run_normalize_address(data) - self.assertEquals(error_str, "", error_str) + self.assertEqual(error_str, "", error_str) def test_normalize_address_invalid_netmask(self): '''Test normalize_address() with invalid_netmask''' @@ -604,7 +604,7 @@ class UtilTestCase(unittest.TestCase): if sys.version_info[0] >= 3: search = bytes(search, 'ascii') out = bytes(out, 'ascii') - self.assertEquals(out, search) + self.assertEqual(out, search) ufw.util.msg_output.close() ufw.util.msg_output = None @@ -651,19 +651,19 @@ class UtilTestCase(unittest.TestCase): def test_cmd(self): '''Test cmd()''' (rc, report) = ufw.util.cmd(['ls', '/']) - self.assertEquals(rc, 0, "Unexpected return code: %d" % rc) + self.assertEqual(rc, 0, "Unexpected return code: %d" % rc) self.assertTrue('etc' in report, "Could not find 'etc'in:\n%s" % \ report) (rc, report) = ufw.util.cmd(['./nonexistent-command']) - self.assertEquals(rc, 127, "Unexpected return code: %d" % rc) + self.assertEqual(rc, 127, "Unexpected return code: %d" % rc) def test_cmd_pipe(self): '''Test cmd_pipe()''' (rc, report) = ufw.util.cmd_pipe(['ls', '/'], ['grep', '-q', 'etc']) - self.assertEquals(rc, 0, "Unexpected return code: %d" % rc) + self.assertEqual(rc, 0, "Unexpected return code: %d" % rc) (rc, report) = ufw.util.cmd_pipe(['./nonexistent-command'], ['grep', '-q', 'etc']) - self.assertEquals(rc, 127, "Unexpected return code: %d" % rc) + self.assertEqual(rc, 127, "Unexpected return code: %d" % rc) def test_error(self): '''Test error()''' @@ -690,7 +690,7 @@ class UtilTestCase(unittest.TestCase): if sys.version_info[0] >= 3: search = bytes(search, 'ascii') out = bytes(out, 'ascii') - self.assertEquals(out, search) + self.assertEqual(out, search) ufw.util.msg_output.close() ufw.util.msg_output = None @@ -706,7 +706,7 @@ class UtilTestCase(unittest.TestCase): '''Test word_wrap()''' s = ufw.util.word_wrap("foo\nbar baz", 3) expected = "foo\nbar\nbaz" - self.assertEquals(s, expected, "'%s' != '%s'" % (s, expected)) + self.assertEqual(s, expected, "'%s' != '%s'" % (s, expected)) def test_wrap_text(self): '''Test wrap_text()''' @@ -718,7 +718,7 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAA ''' s = ufw.util.wrap_text(t) - self.assertEquals(s, expected, "'%s' != '%s'" % (s, expected)) + self.assertEqual(s, expected, "'%s' != '%s'" % (s, expected)) def test_human_sort(self): '''Test human_sort()''' @@ -728,13 +728,13 @@ AAA tmp = s.split(',') ufw.util.human_sort(tmp) res = ",".join(tmp) - self.assertEquals(str(res), expected) + self.assertEqual(str(res), expected) def test_get_ppid(self): '''Test get_ppid()''' ufw.util.get_ppid() ppid = ufw.util.get_ppid(1) - self.assertEquals(ppid, 0, "%d' != '0'" % ppid) + self.assertEqual(ppid, 0, "%d' != '0'" % ppid) tests.unit.support.check_for_exception(self, ValueError, \ ufw.util.get_ppid, 'a') @@ -751,7 +751,7 @@ AAA with unittest.mock.patch("builtins.open", m): with unittest.mock.patch("os.path.isfile", return_value=True): ppid = ufw.util.get_ppid(9983) - self.assertEquals(ppid, 923, "%d' != '923'" % ppid) + self.assertEqual(ppid, 923, "%d' != '923'" % ppid) def test_get_ppid_with_space(self): """Test get_ppid() with space""" @@ -763,7 +763,7 @@ AAA with unittest.mock.patch("builtins.open", m): with unittest.mock.patch("os.path.isfile", return_value=True): ppid = ufw.util.get_ppid(9983) - self.assertEquals(ppid, 923, "%d' != '923'" % ppid) + self.assertEqual(ppid, 923, "%d' != '923'" % ppid) def test_get_ppid_with_parens(self): """Test get_ppid() with parens""" @@ -775,7 +775,7 @@ AAA with unittest.mock.patch("builtins.open", m): with unittest.mock.patch("os.path.isfile", return_value=True): ppid = ufw.util.get_ppid(9983) - self.assertEquals(ppid, 923, "%d' != '923'" % ppid) + self.assertEqual(ppid, 923, "%d' != '923'" % ppid) def test_under_ssh(self): '''Test under_ssh()''' @@ -844,7 +844,7 @@ AAA cidr = str(m) dotted = ufw.util._cidr_to_dotted_netmask(cidr, False) reverse = ufw.util._dotted_netmask_to_cidr(dotted, False) - self.assertEquals(cidr, reverse, + self.assertEqual(cidr, reverse, "cidr=%s, dotted=%s, reverse=%s" % (cidr, dotted, reverse)) @@ -852,9 +852,9 @@ AAA def test__address4_to_network(self): '''Test _address4_to_network()''' n = ufw.util._address4_to_network("192.168.1.1/16") - self.assertEquals(n, "192.168.0.0/16") + self.assertEqual(n, "192.168.0.0/16") n = "192.168.1.1" - self.assertEquals(n, ufw.util._address4_to_network(n)) + self.assertEqual(n, ufw.util._address4_to_network(n)) tests.unit.support.check_for_exception(self, ValueError, \ ufw.util._address4_to_network, '192.168.1.1/16/16') @@ -862,9 +862,9 @@ AAA def test__address6_to_network(self): '''Test _address6_to_network()''' n = ufw.util._address6_to_network("ff81::1/15") - self.assertEquals(n, "ff80::/15") + self.assertEqual(n, "ff80::/15") n = "ff80::1" - self.assertEquals(n, ufw.util._address6_to_network(n)) + self.assertEqual(n, ufw.util._address6_to_network(n)) tests.unit.support.check_for_exception(self, ValueError, \ ufw.util._address6_to_network, 'ff80::1/16/16') @@ -1049,7 +1049,7 @@ AAA expected = '666f6ff09f918d626172e5ad9762617a' result = ufw.util.hex_encode(s) - self.assertEquals(expected, result) + self.assertEqual(expected, result) def test_hex_decode(self): '''Test hex_decode() output''' @@ -1059,7 +1059,7 @@ AAA expected = u'foođź‘Ťbarĺ­—baz' result = ufw.util.hex_decode(s) - self.assertEquals(expected, result) + self.assertEqual(expected, result) # test odd length string mitigation by truncating one hex-digit. This # should result in the last (odd) hex digit being dropped and a decoded @@ -1068,7 +1068,7 @@ AAA if sys.version_info[0] < 3: expected = u"foođź‘Ťbarĺ­—ba" result = ufw.util.hex_decode(s[:-1]) - self.assertEquals(expected, result) + self.assertEqual(expected, result) # test odd length string mitigation by removing first hex-digit. This # should result in the last (odd) hex digit being dropped, but since @@ -1078,7 +1078,7 @@ AAA if sys.version_info[0] < 3: expected = u"f\\xf6\\xff\t\\xf9\x18\\xd6&\x17.Z\\xd9v&\x17" result = ufw.util.hex_decode(s[1:]) - self.assertEquals(expected, result) + self.assertEqual(expected, result) def test_create_lock(self): '''Test create_lock()''' -- 2.45.2