jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] Remove code duplication in link_tests.py

Change-Id: Ifedf792dc5b6d7156952e31800d1aeb7d535beb8
---
M tests/link_tests.py
1 file changed, 22 insertions(+), 30 deletions(-)

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):

To view, visit change 675829. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ifedf792dc5b6d7156952e31800d1aeb7d535beb8
Gerrit-Change-Number: 675829
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: DannyS712 <dannys712.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged