예제 #1
0
 def test_IWM(self):
     """Test the load_site method for MW sites on the IWM list."""
     data = self.get_site().siteinfo['interwikimap']
     for item in data:
         if 'local' not in item:
             url = item['url']
             self.all += [url]
             try:
                 site = MWSite(url)
             except Exception as error:
                 print('failed to load ' + url)
                 self.errors[url] = error
                 continue
             if type(site) is MWSite:
                 try:
                     version = site.version
                 except Exception as error:
                     print('failed to get version of ' + url)
                     self.errors[url] = error
                 else:
                     try:
                         self.assertIsInstance(version, basestring)
                         self.assertRegex(version, r'^\d\.\d+.*')
                         self.passes[url] = site
                     except AssertionError as error:
                         print('failed to parse version of ' + url)
                         self.failures[url] = error
예제 #2
0
 def _wiki_detection(self, url, result):
     """Perform one load test."""
     self.all += [url]
     if url in self._urls_tested:
         msg = 'Testing URL "{0}" multiple times!'.format(url)
         if self.allow_multiple:
             print(msg)
         else:
             self.errors[url] = msg
             return
     self._urls_tested.add(url)
     try:
         site = MWSite(url)
     except (ServerError, Timeout) as e:
         self.skips[url] = e
         return
     except Exception as e:
         print('failure {0} on {1}: {2}'.format(url, type(e), e))
         self.errors[url] = e
         return
     try:
         if result is None:
             self.assertIsNone(site)
         else:
             self.assertIsInstance(site, result)
         self.passes[url] = site
     except AssertionError as error:
         self.failures[url] = error
예제 #3
0
    def assertSite(self, url: str):
        """
        Assert a MediaWiki site can be loaded from the url.

        :param url: Url of tested site
        :raises AssertionError: Site under url is not MediaWiki powered
        """
        try:
            self.assertIsInstance(MWSite(url), MWSite)
        except (ServerError, requests_exceptions.Timeout) as e:
            self.skipTest(e)
예제 #4
0
    def assertSite(self, url):
        """
        Assert a MediaWiki site can be loaded from the url.

        @param url: Url of tested site
        @type url: str
        @raises AssertionError: Site under url is not MediaWiki powered
        """
        try:
            self.assertIsInstance(MWSite(url), MWSite)
        except (ServerError, Timeout, ConnectionError) as e:
            self.skipTest(e)
    def assertNoSite(self, url: str):
        """
        Assert a url is not a MediaWiki site.

        @param url: Url of tested site
        @raises AssertionError: Site under url is MediaWiki powered
        """
        with self.assertRaises((AttributeError, ConnectionError, RuntimeError,
                                ServerError, Timeout)) as e:
            MWSite(url)
        unittest_print(
            '\nassertNoSite expected exception:\n{e!r}'.format(e=e.exception))
예제 #6
0
 def _wiki_detection(self, url, result):
     """Perform one load test."""
     self.all += [url]
     try:
         site = MWSite(url)
     except Exception as e:
         print('failed on ' + url)
         self.errors[url] = e
         return
     try:
         if result is None:
             self.assertIsNone(site)
         else:
             self.assertIsInstance(site, result)
         self.passes[url] = result
     except AssertionError as error:
         self.failures[url] = error
예제 #7
0
    def test_T235768_failure(self):
        """Test generate_family_file works for private wikis.

        generate_family_file.FamilyFileGenerator.run() does:
          w = self.Wiki(self.base_url)
          self.wikis[w.lang] = w

        where self.Wiki is pywikibot.site_detect.MWSite.__init__.
        That calls MWSite._parse_post_117() which sets lang, but
        that call's wrapped to log exceptions and then continue
        past them.  In T235768, the code that handles private
        wikis raises an exception that's consumed in that way.
        The value returned to FamilyFileGenerator.run() does not
        have lang set, causing generate_family_file to bomb.
        """
        site = MWSite(self._weburl)
        self.assertIsInstance(site, MWSite)
        self.assertTrue(hasattr(site, 'lang'))
        self.assertEqual(site.lang, self.LANG)