From c9c995e7f3d3290f0886d482861231145dc3777e Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Fri, 27 Mar 2015 09:38:00 -0400 Subject: [PATCH] NodeconQueryTest: Change IP criteria to skip on Python < 3.3 --- setools/nodeconquery.py | 4 ++-- tests/nodeconquery.py | 44 +++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/setools/nodeconquery.py b/setools/nodeconquery.py index c0314e3..b91c8e5 100644 --- a/setools/nodeconquery.py +++ b/setools/nodeconquery.py @@ -98,7 +98,7 @@ class NodeconQuery(contextquery.ContextQuery): except NameError: # pragma: no cover # Should never actually hit this since the self.network # setter raises the same exception. - raise RuntimeError("IP address/network functions require Python 3.3+.") + raise RuntimeError("Nodecon IP address/network functions require Python 3.3+.") # Python 3.3's IPv6Network constructor does not support # expanded netmasks, only CIDR numbers. Convert netmask @@ -162,7 +162,7 @@ class NodeconQuery(contextquery.ContextQuery): try: self.network = ipaddress.ip_network(net) except NameError: # pragma: no cover - raise RuntimeError("IP address/network functions require Python 3.3+.") + raise RuntimeError("Nodecon IP address/network functions require Python 3.3+.") else: # ensure self.network is set self.network = None diff --git a/tests/nodeconquery.py b/tests/nodeconquery.py index f6c3762..e1d3cdb 100644 --- a/tests/nodeconquery.py +++ b/tests/nodeconquery.py @@ -214,46 +214,34 @@ class NodeconQueryTest(unittest.TestCase): nodecons = sorted(n.address for n in q.results()) self.assertListEqual(["10.1.55.1"], nodecons) + @unittest.skipIf(sys.version_info < (3, 3), "Requries Python 3.3+.") def test_100_v4network_equal(self): """Nodecon query with IPv4 equal network""" - if sys.version_info < (3, 3): - self.assertRaises( - RuntimeError, NodeconQuery, self.p, net="10.1.100.0/24", net_overlap=False) - else: - q = NodeconQuery(self.p, net="10.1.100.0/24", net_overlap=False) + q = NodeconQuery(self.p, net="10.1.100.0/24", net_overlap=False) - nodecons = sorted(n.address for n in q.results()) - self.assertListEqual(["10.1.100.0"], nodecons) + nodecons = sorted(n.address for n in q.results()) + self.assertListEqual(["10.1.100.0"], nodecons) + @unittest.skipIf(sys.version_info < (3, 3), "Requries Python 3.3+.") def test_101_v4network_overlap(self): """Nodecon query with IPv4 network overlap""" - if sys.version_info < (3, 3): - self.assertRaises( - RuntimeError, NodeconQuery, self.p, net="10.1.101.128/25", net_overlap=True) - else: - q = NodeconQuery(self.p, net="10.1.101.128/25", net_overlap=True) + q = NodeconQuery(self.p, net="10.1.101.128/25", net_overlap=True) - nodecons = sorted(n.address for n in q.results()) - self.assertListEqual(["10.1.101.0"], nodecons) + nodecons = sorted(n.address for n in q.results()) + self.assertListEqual(["10.1.101.0"], nodecons) + @unittest.skipIf(sys.version_info < (3, 3), "Requries Python 3.3+.") def test_110_v6network_equal(self): """Nodecon query with IPv6 equal network""" - if sys.version_info < (3, 3): - self.assertRaises( - RuntimeError, NodeconQuery, self.p, net="1100::/16", net_overlap=False) - else: - q = NodeconQuery(self.p, net="1100::/16", net_overlap=False) + q = NodeconQuery(self.p, net="1100::/16", net_overlap=False) - nodecons = sorted(n.address for n in q.results()) - self.assertListEqual(["1100::"], nodecons) + nodecons = sorted(n.address for n in q.results()) + self.assertListEqual(["1100::"], nodecons) + @unittest.skipIf(sys.version_info < (3, 3), "Requries Python 3.3+.") def test_111_v6network_overlap(self): """Nodecon query with IPv6 network overlap""" - if sys.version_info < (3, 3): - self.assertRaises( - RuntimeError, NodeconQuery, self.p, net="1110:8000::/17", net_overlap=True) - else: - q = NodeconQuery(self.p, net="1110:8000::/17", net_overlap=True) + q = NodeconQuery(self.p, net="1110:8000::/17", net_overlap=True) - nodecons = sorted(n.address for n in q.results()) - self.assertListEqual(["1110::"], nodecons) + nodecons = sorted(n.address for n in q.results()) + self.assertListEqual(["1110::"], nodecons)