jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/675829 )
Change subject: [tests] Remove code duplication in link_tests.py ......................................................................
[tests] Remove code duplication in link_tests.py
Change-Id: Ifedf792dc5b6d7156952e31800d1aeb7d535beb8 --- M tests/link_tests.py 1 file changed, 22 insertions(+), 30 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/link_tests.py b/tests/link_tests.py index d3550bc..0ecd64b 100644 --- a/tests/link_tests.py +++ b/tests/link_tests.py @@ -795,37 +795,29 @@ config.mylang = 'en' config.family = 'wikipedia'
- def test_fully_qualified_NS0_code(self): - """Test 'testwiki:wikidata:Q6' on enwp is namespace 0.""" - link = Link('testwiki:wikidata:Q6') - link.parse() - self.assertEqual(link.site, pywikibot.Site('wikidata', 'wikidata')) - self.assertEqual(link.title, 'Q6') - self.assertEqual(link.namespace, 0) + def test_fully_qualified_NS0(self): + """Test prefixed links with 'Q6' on enwp is namespace 0.""" + test = [('testwiki:wikidata', 'wikidata:wikidata'), + ('wikidata:testwiki', 'wikipedia:test')] + for linkprefix, sitetitle in test: + with self.subTest(pattern=linkprefix): + link = Link(linkprefix + ':Q6') + link.parse() + self.assertEqual(link.site, pywikibot.Site(sitetitle)) + self.assertEqual(link.title, 'Q6') + self.assertEqual(link.namespace, 0)
- def test_fully_qualified_NS1_code(self): - """Test 'testwiki:wikidata:Talk:Q6' on enwp is namespace 1.""" - link = Link('testwiki:wikidata:Talk:Q6') - link.parse() - self.assertEqual(link.site, pywikibot.Site('wikidata', 'wikidata')) - self.assertEqual(link.title, 'Q6') - self.assertEqual(link.namespace, 1) - - def test_fully_qualified_NS0_family(self): - """Test 'wikidata:testwiki:Q6' on enwp is namespace 0.""" - link = Link('wikidata:testwiki:Q6') - link.parse() - self.assertEqual(link.site, pywikibot.Site('test', 'wikipedia')) - self.assertEqual(link.title, 'Q6') - self.assertEqual(link.namespace, 0) - - def test_fully_qualified_NS1_family(self): - """Test 'wikidata:testwiki:Talk:Q6' on enwp is namespace 1.""" - link = Link('wikidata:testwiki:Talk:Q6') - link.parse() - self.assertEqual(link.site, pywikibot.Site('test', 'wikipedia')) - self.assertEqual(link.title, 'Q6') - self.assertEqual(link.namespace, 1) + def test_fully_qualified_NS1(self): + """Test prefixed links with 'Talk:Q6' on enwp is namespace 1.""" + test = [('testwiki:wikidata', 'wikidata:wikidata'), + ('wikidata:testwiki', 'wikipedia:test')] + for linkprefix, sitetitle in test: + with self.subTest(pattern=linkprefix): + link = Link(linkprefix + ':Talk:Q6') + link.parse() + self.assertEqual(link.site, pywikibot.Site(sitetitle)) + self.assertEqual(link.title, 'Q6') + self.assertEqual(link.namespace, 1)
class TestFullyQualifiedOneSiteFamilyImplicitLinkParser(LinkTestCase):
pywikibot-commits@lists.wikimedia.org