jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/626845 )
Change subject: [bugfix] Fix wikibase_tests.py after 20a03d272d ......................................................................
[bugfix] Fix wikibase_tests.py after 20a03d272d
- use _test_new_empty in DataCollectionTestCase which is called by each subclass - use self.assertIsEmpty(result) instead of self.assertLength(result, 0) - self.assert(Not)In(attr, item.__dict__) to verify that an attribute exists. hasattr() would load the attributes. - use subTests
Change-Id: I5f6e9b4f771fcbcd4550e52c73201ead22def8c2 --- M tests/wikibase_tests.py 1 file changed, 26 insertions(+), 15 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index fdae3c1..0076ddd28 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -55,19 +55,6 @@ self.assertLength(set(list_of_dupes), 1)
-class DataCollectionTestCase(WikidataTestCase): - - """Test case for a Wikibase collection class.""" - - collection_class = None - - def test_new_empty(self): - """Test that new_empty method returns empty collection.""" - cls = self.collection_class - result = cls.new_empty(self.get_repo()) - self.assertLength(result, 0) - - class TestLoadRevisionsCaching(BasePageLoadRevisionsCachingTestBase, WikidataTestCase):
@@ -969,11 +956,14 @@ attrs = ['_content', 'labels', 'descriptions', 'aliases', 'claims', 'sitelinks'] for attr in attrs: - self.assertFalse(hasattr(item, attr)) + with self.subTest(attr=attr, note='before loading'): + # hasattr() loads the attributes; use item.__dict__ for tests + self.assertNotIn(attr, item.__dict__)
item.labels # trigger loading for attr in attrs: - self.assertTrue(hasattr(item, attr)) + with self.subTest(attr=attr, note='after loading'): + self.assertIn(attr, item.__dict__)
def test_load_item_set_id(self): """Test setting item.id attribute on empty item.""" @@ -1789,6 +1779,19 @@ self.assertLength(wvlinks, 2)
+class DataCollectionTestCase(WikidataTestCase): + + """Test case for a Wikibase collection class.""" + + collection_class = None + + def _test_new_empty(self): + """Test that new_empty method returns empty collection.""" + cls = self.collection_class + result = cls.new_empty(self.get_repo()) + self.assertIsEmpty(result) + + class TestLanguageDict(DataCollectionTestCase):
"""Test cases covering LanguageDict methods.""" @@ -1865,6 +1868,10 @@ LanguageDict.normalizeData(self.lang_out), {'en': {'language': 'en', 'value': 'foo'}})
+ def test_new_empty(self): + """Test that new_empty method returns empty collection.""" + self._test_new_empty() +
class TestAliasesDict(DataCollectionTestCase):
@@ -1962,6 +1969,10 @@ ]} self.assertEqual(AliasesDict.normalizeData(data_in), data_out)
+ def test_new_empty(self): + """Test that new_empty method returns empty collection.""" + self._test_new_empty() +
class TestWriteNormalizeData(TestCase):
pywikibot-commits@lists.wikimedia.org