jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/524210 )

Change subject: fix(test_family): deprecate test_family
......................................................................

fix(test_family): deprecate test_family

We have two families that both define test.wikipedia.org and this
has created some issues. (see the tasks below)

test_family.py:
- deprecate this module
- replace the Family with a new class that inherits from the
  wikipedia_family.Family

family.py:
- test_family.Family was the only family using the private
  `_ignore_from_url` attribute. Remove all the usages of this attriube.

family_tests.py:
- remove the assertions of test family that do not apply now that
  test family is inheriting from wikipedia family.
- remove usages of `_ignore_from_url` attribute.

pywikibot.__init__:
- to avoid the newly added deprecation warning of test family when
  `pywikibot.Site(url='https://test.wikipedia.org/w/index.php')` is
  used, prevent loading that family and let the code continue to
  look for the right family (wikipedia).

generate_user_files_test.py:
- Update test_get_site_and_lang to use wikisource. (we could also just
  change self.assertEqual(code, 'test') to self.assertEqual(code, 'en'),
  but that will live the DeprecationWarning.

link_test.py:
- Use Site('test', 'wikipedia') instead of the deprecated
  pywikibot.Site('test', 'test'). Note these two are still not equal.

Bug: T228375
Bug: T228300
Change-Id: I7b65fca0a451422e5acbe64f80549f6f49646482
---
M pywikibot/__init__.py
M pywikibot/families/test_family.py
M pywikibot/family.py
M tests/family_tests.py
M tests/generate_user_files_tests.py
M tests/link_tests.py
6 files changed, 18 insertions(+), 29 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 7a6b267..662e746 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -1174,6 +1174,8 @@
         # Iterate through all families and look, which does apply to
         # the given URL
         for fam in config.family_files:
+            if fam == 'test':  # test_family.py is deprecated
+                continue
             family = Family.load(fam)
             code = family.from_url(url)
             if code is not None:
diff --git a/pywikibot/families/test_family.py 
b/pywikibot/families/test_family.py
index a1ea3e0..51b4480 100644
--- a/pywikibot/families/test_family.py
+++ b/pywikibot/families/test_family.py
@@ -7,17 +7,17 @@
 #
 from __future__ import absolute_import, division, unicode_literals

-from pywikibot import family
+from pywikibot.families.wikipedia_family import Family
+from pywikibot.tools import issue_deprecation_warning
+
+issue_deprecation_warning(
+    'test_family', 'wikipedia_family', since='20190718')
+# Also remove the ``if fam == 'test':`` condition in pywikibot.__init__
+# whenever this module is removed.


-# The test wikipedia family
-class Family(family.SingleSiteFamily, family.WikimediaFamily):
+class Family(Family):

     """Family class for test.wikipedia.org."""

     name = 'test'
-    domain = 'test.wikipedia.org'
-    interwiki_forward = 'wikipedia'
-
-    # 'test' family should resolve to be in the 'wikipedia' family
-    _ignore_from_url = True
diff --git a/pywikibot/family.py b/pywikibot/family.py
index d34938a..421d70e 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1264,9 +1264,6 @@

         return config.site_interface

-    # List of codes which aren't returned by from_url; True returns None always
-    _ignore_from_url = []
-
     def from_url(self, url):
         """
         Return whether this family matches the given url.
@@ -1291,9 +1288,6 @@
             which would work with the given URL.
         @raises ValueError: When text is present after $1.
         """
-        if self._ignore_from_url is True:
-            return None
-
         parsed = urlparse.urlparse(url)
         if not re.match('(https?)?$', parsed.scheme):
             return None
@@ -1316,8 +1310,6 @@

         matched_sites = []
         for code in chain(self.codes, getattr(self, 'test_codes', ())):
-            if code in self._ignore_from_url:
-                continue
             if self._hostname(code)[1] == parsed.netloc:
                 # Use the code and family instead of the url
                 # This is only creating a Site instance if domain matches
diff --git a/tests/family_tests.py b/tests/family_tests.py
index 8361090..aad18c9 100644
--- a/tests/family_tests.py
+++ b/tests/family_tests.py
@@ -124,8 +124,6 @@
         family = Family.load('test')
         self.assertIn('dk', family.obsolete)
         self.assertIn('dk', family.interwiki_replacements)
-        self.assertEqual(family.obsolete, family.interwiki_replacements)
-        self.assertEqual(family.interwiki_removals, set())

     def test_set_obsolete(self):
         """Test obsolete can be set."""
@@ -251,11 +249,7 @@
                                                  family.path(code)))
                     # Families can switch off if they want to be detected using
                     # URL. This applies for test:test (there is test:wikipedia)
-                    if (family._ignore_from_url
-                            or code in family._ignore_from_url):
-                        self.assertIsNone(family.from_url(url))
-                    else:
-                        self.assertEqual(family.from_url(url), code)
+                    self.assertEqual(family.from_url(url), code)


 class TestOldFamilyMethod(DeprecationTestCase):
diff --git a/tests/generate_user_files_tests.py 
b/tests/generate_user_files_tests.py
index f0625cb..dd0efe4 100644
--- a/tests/generate_user_files_tests.py
+++ b/tests/generate_user_files_tests.py
@@ -61,10 +61,11 @@
     def test_get_site_and_lang(self):
         """Test get_site_and_lang function with parameters."""
         family, code, user = guf.get_site_and_lang(
-            default_family='test', default_lang='foo', default_username='bar',
+            default_family='wikisource', default_lang='foo',
+            default_username='bar',
             force=True)
-        self.assertEqual(family, 'test')
-        self.assertEqual(code, 'test')
+        self.assertEqual(family, 'wikisource')
+        self.assertEqual(code, 'en')
         self.assertEqual(user, 'bar')

     def test_parse_sections(self):
diff --git a/tests/link_tests.py b/tests/link_tests.py
index 180dcf5..1307ac8 100644
--- a/tests/link_tests.py
+++ b/tests/link_tests.py
@@ -528,7 +528,7 @@
             'code': 'en'
         },
         'test.wp': {
-            'family': 'test',
+            'family': 'wikipedia',
             'code': 'test'
         },
     }
@@ -891,7 +891,7 @@
         config.family = 'wikipedia'
         link = Link('wikidata:testwiki:Q6')
         link.parse()
-        self.assertEqual(link.site, pywikibot.Site('test', 'test'))
+        self.assertEqual(link.site, pywikibot.Site('test', 'wikipedia'))
         self.assertEqual(link.title, 'Q6')
         self.assertEqual(link.namespace, 0)

@@ -901,7 +901,7 @@
         config.family = 'wikipedia'
         link = Link('wikidata:testwiki:Talk:Q6')
         link.parse()
-        self.assertEqual(link.site, pywikibot.Site('test', 'test'))
+        self.assertEqual(link.site, pywikibot.Site('test', 'wikipedia'))
         self.assertEqual(link.title, 'Q6')
         self.assertEqual(link.namespace, 1)
 

--
To view, visit https://gerrit.wikimedia.org/r/524210
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I7b65fca0a451422e5acbe64f80549f6f49646482
Gerrit-Change-Number: 524210
Gerrit-PatchSet: 8
Gerrit-Owner: Dalba <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to