[MediaWiki-commits] [Gerrit] operations...cumin[master]: Tests: convert unittest to pytest
Volans has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/361274 ) Change subject: Tests: convert unittest to pytest .. Tests: convert unittest to pytest Bug: T154588 Change-Id: Ia75f32b212e36d613c784765a52f1317ac690810 --- M cumin/tests/unit/backends/test_direct.py M cumin/tests/unit/backends/test_puppetdb.py M cumin/tests/unit/test_backends.py M cumin/tests/unit/test_cli.py M cumin/tests/unit/test_grammar.py M cumin/tests/unit/test_query.py M cumin/tests/unit/test_transport.py M cumin/tests/unit/transports/test_clustershell.py M cumin/tests/unit/transports/test_init.py 9 files changed, 563 insertions(+), 570 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/software/cumin refs/changes/74/361274/1 diff --git a/cumin/tests/unit/backends/test_direct.py b/cumin/tests/unit/backends/test_direct.py index feaea9b..d63440b 100644 --- a/cumin/tests/unit/backends/test_direct.py +++ b/cumin/tests/unit/backends/test_direct.py @@ -1,80 +1,77 @@ """Direct backend tests.""" -import unittest +import pytest from ClusterShell.NodeSet import NodeSet from cumin.backends import BaseQuery, InvalidQueryError, direct -class TestDirectQueryClass(unittest.TestCase): -"""Direct backend query_class test class.""" - -def test_query_class(self): -"""An instance of query_class should be an instance of BaseQuery.""" -query = direct.query_class({}) -self.assertIsInstance(query, BaseQuery) +def test_direct_query_class(): +"""An instance of query_class should be an instance of BaseQuery.""" +query = direct.query_class({}) +assert isinstance(query, BaseQuery) -class TestDirectQuery(unittest.TestCase): +class TestDirectQuery(object): """Direct backend query test class.""" -def setUp(self): -"""Setup an instace of DirectQuery for each test.""" -self.query = direct.DirectQuery({}) +def setup_method(self, _): +"""Setup an instance of DirectQuery for each test.""" +self.query = direct.DirectQuery({}) # pylint: disable=attribute-defined-outside-init def test_instantiation(self): """An instance of DirectQuery should be an instance of BaseQuery.""" -self.assertIsInstance(self.query, BaseQuery) -self.assertDictEqual(self.query.config, {}) +assert isinstance(self.query, BaseQuery) +assert self.query.config == {} def test_add_category_fact(self): """Calling add_category() should raise InvalidQueryError.""" -with self.assertRaisesRegexp(InvalidQueryError, r"Category tokens are not supported"): +with pytest.raises(InvalidQueryError, match='Category tokens are not supported'): self.query.add_category('F', 'key', 'value') def test_add_hosts(self): """Calling add_hosts() should add the hosts to the NodeSet.""" -self.assertListEqual(list(self.query.hosts), []) +assert list(self.query.hosts) == [] # No hosts self.query.add_hosts(NodeSet.fromlist([])) -self.assertListEqual(list(self.query.hosts), []) +assert list(self.query.hosts) == [] # Single host self.query.add_hosts(NodeSet.fromlist(['host'])) -self.assertListEqual(list(self.query.hosts), ['host']) +assert list(self.query.hosts) == ['host'] # Multiple hosts self.query.add_hosts(NodeSet.fromlist(['host1', 'host2'])) -self.assertListEqual(list(self.query.hosts), ['host', 'host1', 'host2']) +assert list(self.query.hosts) == ['host', 'host1', 'host2'] # Negated query self.query.add_hosts(NodeSet.fromlist(['host1']), neg=True) -self.assertListEqual(list(self.query.hosts), ['host', 'host2']) +assert list(self.query.hosts) == ['host', 'host2'] # Globbing is not supported -with self.assertRaisesRegexp(InvalidQueryError, r"Hosts globbing is not supported"): +with pytest.raises(InvalidQueryError, match='Hosts globbing is not supported'): self.query.add_hosts(NodeSet.fromlist(['host1*'])) def test_open_subgroup(self): """Calling open_subgroup() should raise InvalidQueryError.""" -with self.assertRaisesRegexp(InvalidQueryError, r"Subgroups are not supported"): +with pytest.raises(InvalidQueryError, matach='Subgroups are not supported'): self.query.open_subgroup() def test_close_subgroup(self): """Calling close_subgroup() should raise InvalidQueryError.""" -with self.assertRaisesRegexp(InvalidQueryError, r"Subgroups are not supported"): +with pytest.raises(InvalidQueryError, match='Subgroups are not supported'): self.query.close_subgroup() def test_add_and(self): """Calling add_and() should raise InvalidQueryError.""" -with self.assertRaisesRegexp(InvalidQueryError, r"Boolean AND op
[MediaWiki-commits] [Gerrit] operations...cumin[master]: Tests: convert unittest to pytest
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/361274 ) Change subject: Tests: convert unittest to pytest .. Tests: convert unittest to pytest Bug: T154588 Change-Id: Ia75f32b212e36d613c784765a52f1317ac690810 --- M cumin/tests/unit/backends/test_direct.py M cumin/tests/unit/backends/test_puppetdb.py M cumin/tests/unit/test_backends.py M cumin/tests/unit/test_cli.py M cumin/tests/unit/test_grammar.py M cumin/tests/unit/test_query.py M cumin/tests/unit/test_transport.py M cumin/tests/unit/transports/test_clustershell.py M cumin/tests/unit/transports/test_init.py 9 files changed, 563 insertions(+), 570 deletions(-) Approvals: Giuseppe Lavagetto: Looks good to me, but someone else must approve jenkins-bot: Verified Volans: Looks good to me, approved diff --git a/cumin/tests/unit/backends/test_direct.py b/cumin/tests/unit/backends/test_direct.py index feaea9b..d63440b 100644 --- a/cumin/tests/unit/backends/test_direct.py +++ b/cumin/tests/unit/backends/test_direct.py @@ -1,80 +1,77 @@ """Direct backend tests.""" -import unittest +import pytest from ClusterShell.NodeSet import NodeSet from cumin.backends import BaseQuery, InvalidQueryError, direct -class TestDirectQueryClass(unittest.TestCase): -"""Direct backend query_class test class.""" - -def test_query_class(self): -"""An instance of query_class should be an instance of BaseQuery.""" -query = direct.query_class({}) -self.assertIsInstance(query, BaseQuery) +def test_direct_query_class(): +"""An instance of query_class should be an instance of BaseQuery.""" +query = direct.query_class({}) +assert isinstance(query, BaseQuery) -class TestDirectQuery(unittest.TestCase): +class TestDirectQuery(object): """Direct backend query test class.""" -def setUp(self): -"""Setup an instace of DirectQuery for each test.""" -self.query = direct.DirectQuery({}) +def setup_method(self, _): +"""Setup an instance of DirectQuery for each test.""" +self.query = direct.DirectQuery({}) # pylint: disable=attribute-defined-outside-init def test_instantiation(self): """An instance of DirectQuery should be an instance of BaseQuery.""" -self.assertIsInstance(self.query, BaseQuery) -self.assertDictEqual(self.query.config, {}) +assert isinstance(self.query, BaseQuery) +assert self.query.config == {} def test_add_category_fact(self): """Calling add_category() should raise InvalidQueryError.""" -with self.assertRaisesRegexp(InvalidQueryError, r"Category tokens are not supported"): +with pytest.raises(InvalidQueryError, match='Category tokens are not supported'): self.query.add_category('F', 'key', 'value') def test_add_hosts(self): """Calling add_hosts() should add the hosts to the NodeSet.""" -self.assertListEqual(list(self.query.hosts), []) +assert list(self.query.hosts) == [] # No hosts self.query.add_hosts(NodeSet.fromlist([])) -self.assertListEqual(list(self.query.hosts), []) +assert list(self.query.hosts) == [] # Single host self.query.add_hosts(NodeSet.fromlist(['host'])) -self.assertListEqual(list(self.query.hosts), ['host']) +assert list(self.query.hosts) == ['host'] # Multiple hosts self.query.add_hosts(NodeSet.fromlist(['host1', 'host2'])) -self.assertListEqual(list(self.query.hosts), ['host', 'host1', 'host2']) +assert list(self.query.hosts) == ['host', 'host1', 'host2'] # Negated query self.query.add_hosts(NodeSet.fromlist(['host1']), neg=True) -self.assertListEqual(list(self.query.hosts), ['host', 'host2']) +assert list(self.query.hosts) == ['host', 'host2'] # Globbing is not supported -with self.assertRaisesRegexp(InvalidQueryError, r"Hosts globbing is not supported"): +with pytest.raises(InvalidQueryError, match='Hosts globbing is not supported'): self.query.add_hosts(NodeSet.fromlist(['host1*'])) def test_open_subgroup(self): """Calling open_subgroup() should raise InvalidQueryError.""" -with self.assertRaisesRegexp(InvalidQueryError, r"Subgroups are not supported"): +with pytest.raises(InvalidQueryError, matach='Subgroups are not supported'): self.query.open_subgroup() def test_close_subgroup(self): """Calling close_subgroup() should raise InvalidQueryError.""" -with self.assertRaisesRegexp(InvalidQueryError, r"Subgroups are not supported"): +with pytest.raises(InvalidQueryError, match='Subgroups are not supported'): self.query.close_subgroup() def test_add_and(self): """Calling add_and() should raise InvalidQueryError.""" -with