예제 #1
0
    def test_repr(self):
        """Test Namespace.__repr__."""
        a = Namespace(id=0, canonical_name='Foo')
        s = repr(a)
        r = 'Namespace(id=0, custom_name={!r}, canonical_name={!r}, ' \
            'aliases=[])'.format(unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        a.defaultcontentmodel = 'bar'
        s = repr(a)
        r = ('Namespace(id=0, custom_name={!r}, canonical_name={!r}, '
             'aliases=[], defaultcontentmodel={!r})'.format(
                 unicode('Foo'), unicode('Foo'), unicode('bar')))
        self.assertEqual(s, r)

        a.case = 'upper'
        s = repr(a)
        r = ('Namespace(id=0, custom_name={!r}, canonical_name={!r}, '
             'aliases=[], case={!r}, defaultcontentmodel={!r})'.format(
                 unicode('Foo'), unicode('Foo'), unicode('upper'),
                 unicode('bar')))
        self.assertEqual(s, r)

        b = eval(repr(a))
        self.assertEqual(a, b)
예제 #2
0
    def test_repr(self):
        """Test Namespace.__repr__."""
        a = Namespace(id=0, canonical_name=u'Foo')
        s = repr(a)
        r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[])" \
            % (unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        a.defaultcontentmodel = 'bar'
        s = repr(a)
        r = ('Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], '
             'defaultcontentmodel=%r)' %
             (unicode('Foo'), unicode('Foo'), unicode('bar')))
        self.assertEqual(s, r)

        a.case = 'upper'
        s = repr(a)
        r = (
            'Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], '
            'case=%r, defaultcontentmodel=%r)' %
            (unicode('Foo'), unicode('Foo'), unicode('upper'), unicode('bar')))
        self.assertEqual(s, r)

        b = eval(repr(a))
        self.assertEqual(a, b)
예제 #3
0
    def testNamespaceCompare(self):
        """Test Namespace comparisons."""
        a = Namespace(id=0, canonical_name='')

        self.assertEqual(a, 0)
        self.assertEqual(a, '')
        self.assertFalse(a < 0)  # noqa: H205
        self.assertFalse(a > 0)  # noqa: H205
        self.assertNotEqual(a, None)  # noqa: H203

        self.assertGreater(a, -1)

        x = Namespace(id=6,
                      custom_name='dummy',
                      canonical_name='File',
                      aliases=['Image', 'Immagine'])
        y = Namespace(id=6,
                      custom_name='ملف',
                      canonical_name='File',
                      aliases=['Image', 'Immagine'])
        z = Namespace(id=7,
                      custom_name='dummy 7',
                      canonical_name='File',
                      aliases=['Image', 'Immagine'])

        self.assertEqual(x, x)
        self.assertEqual(x, y)
        self.assertNotEqual(x, a)
        self.assertNotEqual(x, z)

        self.assertEqual(x, 6)
        self.assertEqual(x, 'dummy')
        self.assertEqual(x, 'Dummy')
        self.assertEqual(x, 'file')
        self.assertEqual(x, 'File')
        self.assertEqual(x, ':File')
        self.assertEqual(x, ':File:')
        self.assertEqual(x, 'File:')
        self.assertEqual(x, 'image')
        self.assertEqual(x, 'Image')

        self.assertFalse(x < 6)  # noqa: H205
        self.assertFalse(x > 6)  # noqa: H205

        self.assertEqual(y, 'ملف')

        self.assertLess(a, x)
        self.assertLess(x, z)
        self.assertLessEqual(a, x)
        self.assertGreater(x, a)
        self.assertGreater(x, 0)
        self.assertGreater(z, x)
        self.assertGreaterEqual(x, a)
        self.assertGreaterEqual(y, x)

        self.assertIn(6, [x, y, z])
        self.assertNotIn(8, [x, y, z])
예제 #4
0
    def test_lookup_name(self):
        """Test Namespace.lookup_name."""
        file_nses = Namespace.builtin_namespaces()

        for name, ns_id in builtin_ns.items():
            file_ns = Namespace.lookup_name(name, file_nses)
            self.assertIsInstance(file_ns, Namespace)
            with self.disable_assert_capture():
                self.assertEqual(file_ns.id, ns_id)
예제 #5
0
    def setUpClass(cls):
        super(TestAlternateNamespaces, cls).setUpClass()

        cls.get_repo()._namespaces = SelfCallDict({
            90: Namespace(id=90,
                          case='first-letter',
                          canonical_name='Item',
                          defaultcontentmodel='wikibase-item'),
            92: Namespace(id=92,
                          case='first-letter',
                          canonical_name='Prop',
                          defaultcontentmodel='wikibase-property')
        })
예제 #6
0
    def test_lookup_name(self):
        """Test Namespace.lookup_name."""
        file_nses = Namespace.builtin_namespaces(use_image_name=False)
        image_nses = Namespace.builtin_namespaces(use_image_name=True)

        for name, ns_id in builtin_ns.items():
            file_ns = Namespace.lookup_name(name, file_nses)
            self.assertIsInstance(file_ns, Namespace)
            image_ns = Namespace.lookup_name(name, image_nses)
            self.assertIsInstance(image_ns, Namespace)
            with self.disable_assert_capture():
                self.assertEqual(file_ns.id, ns_id)
                self.assertEqual(image_ns.id, ns_id)
예제 #7
0
    def testNamespaceToString(self):
        """Test Namespace __str__."""
        ns = Namespace.builtin_namespaces()

        self.assertEqual(str(ns[0]), ':')
        self.assertEqual(str(ns[1]), 'Talk:')
        self.assertEqual(str(ns[6]), ':File:')

        kwargs = {'case': 'first-letter'}
        y = Namespace(id=6, custom_name='ملف', canonical_name='File',
                      aliases=['Image', 'Immagine'], **kwargs)

        self.assertEqual(str(y), ':File:')
        self.assertEqual(y.canonical_prefix(), ':File:')
        self.assertEqual(y.custom_prefix(), ':ملف:')
예제 #8
0
 def __init__(self, code, fam, user, sysop):
     """Constructor."""
     super(DrySite, self).__init__(code, fam, user, sysop)
     self._userinfo = pywikibot.tools.EMPTY_DEFAULT
     self._siteinfo = DummySiteinfo({})
     self._siteinfo._cache['lang'] = (code, True)
     self._namespaces = SelfCallDict(Namespace.builtin_namespaces())
예제 #9
0
 def __init__(self, code, fam, user, sysop):
     """Constructor."""
     super(DrySite, self).__init__(code, fam, user, sysop)
     self._userinfo = pywikibot.tools.EMPTY_DEFAULT
     self._siteinfo = DummySiteinfo({})
     self._siteinfo._cache['lang'] = (code, True)
     self._namespaces = SelfCallDict(Namespace.builtin_namespaces())
예제 #10
0
 def _build_namespaces(self):
     namespaces = super(DryDataSite, self)._build_namespaces()
     namespaces[0].defaultcontentmodel = 'wikibase-item'
     namespaces[120] = Namespace(id=120,
                                 case='first-letter',
                                 canonical_name='Property',
                                 defaultcontentmodel='wikibase-property')
     return namespaces
예제 #11
0
    def testNamespaceCompare(self):
        a = Namespace(id=0, canonical_name=u'')

        self.assertEqual(a, 0)
        self.assertEqual(a, '')
        self.assertNotEqual(a, None)

        x = Namespace(id=6,
                      custom_name=u'dummy',
                      canonical_name=u'File',
                      aliases=[u'Image', u'Immagine'])
        y = Namespace(id=6,
                      custom_name=u'ملف',
                      canonical_name=u'File',
                      aliases=[u'Image', u'Immagine'])
        z = Namespace(id=7,
                      custom_name=u'dummy',
                      canonical_name=u'File',
                      aliases=[u'Image', u'Immagine'])

        self.assertEqual(x, x)
        self.assertEqual(x, y)
        self.assertNotEqual(x, a)
        self.assertNotEqual(x, z)

        self.assertEqual(x, 6)
        self.assertEqual(x, u'dummy')
        self.assertEqual(x, u'Dummy')
        self.assertEqual(x, u'file')
        self.assertEqual(x, u'File')
        self.assertEqual(x, u':File')
        self.assertEqual(x, u':File:')
        self.assertEqual(x, u'File:')
        self.assertEqual(x, u'image')
        self.assertEqual(x, u'Image')

        self.assertEqual(y, u'ملف')

        self.assertLess(a, x)
        self.assertGreater(x, a)
        self.assertGreater(z, x)

        self.assertIn(6, [x, y, z])
        self.assertNotIn(8, [x, y, z])
예제 #12
0
    def test_set_minus(self):
        """Test performing set minus operation on set of Namespace objects."""
        namespaces = Namespace.builtin_namespaces()

        excluded_namespaces = {-1, -2}

        positive_namespaces = set(namespaces) - excluded_namespaces

        self.assertLength(namespaces,
                          len(positive_namespaces) + len(excluded_namespaces))
예제 #13
0
    def test_set_minus(self):
        """Test performing set minus operation on set of Namespace objects."""
        namespaces = Namespace.builtin_namespaces(use_image_name=False)

        excluded_namespaces = {-1, -2}

        positive_namespaces = set(namespaces) - excluded_namespaces

        self.assertEqual(len(namespaces),
                         len(positive_namespaces) + len(excluded_namespaces))
예제 #14
0
 def _build_namespaces(self):
     ns_dict = Namespace.builtin_namespaces(case=self.siteinfo['case'])
     if hasattr(self.family, 'authornamespaces'):
         assert len(self.family.authornamespaces[self.code]) <= 1
         if self.family.authornamespaces[self.code]:
             author_ns = self.family.authornamespaces[self.code][0]
             assert author_ns not in ns_dict
             ns_dict[author_ns] = Namespace(
                 author_ns, 'Author', case=self.siteinfo['case'])
     return ns_dict
예제 #15
0
    def test_set_minus(self):
        """Test performing set minus operation on set of Namespace objects."""
        namespaces = Namespace.builtin_namespaces(use_image_name=False)

        excluded_namespaces = set([-1, -2])

        positive_namespaces = set(namespaces) - excluded_namespaces

        self.assertEqual(len(namespaces),
                         len(positive_namespaces) + len(excluded_namespaces))
예제 #16
0
    def test_repr(self):
        """Test Namespace.__repr__."""
        a = Namespace(id=0, canonical_name='Foo')
        s = repr(a)
        r = 'Namespace(id=0, custom_name={foo!r}, canonical_name={foo!r}, ' \
            'aliases=[])'.format(foo='Foo')
        self.assertEqual(s, r)

        a.defaultcontentmodel = 'bar'
        s = repr(a)
        r = ('Namespace(id=0, custom_name={foo!r}, canonical_name={foo!r}, '
             'aliases=[], defaultcontentmodel={bar!r})'
             .format(foo='Foo', bar='bar'))
        self.assertEqual(s, r)

        a.case = 'upper'
        s = repr(a)
        r = ('Namespace(id=0, custom_name={foo!r}, canonical_name={foo!r}, '
             'aliases=[], case={case!r}, defaultcontentmodel={bar!r})'
             .format(foo='Foo', case='upper', bar='bar'))
예제 #17
0
    def testNamespaceToString(self):
        ns = Namespace.builtin_namespaces(use_image_name=False)

        self.assertEqual(str(ns[0]), ':')
        self.assertEqual(str(ns[1]), 'Talk:')
        self.assertEqual(str(ns[6]), ':File:')

        self.assertEqual(unicode(ns[0]), u':')
        self.assertEqual(unicode(ns[1]), u'Talk:')
        self.assertEqual(unicode(ns[6]), u':File:')

        kwargs = {u'case': u'first-letter'}
        y = Namespace(id=6, custom_name=u'ملف', canonical_name=u'File',
                      aliases=[u'Image', u'Immagine'], **kwargs)

        self.assertEqual(str(y), ':File:')
        if sys.version_info[0] <= 2:
            self.assertEqual(unicode(y), u':ملف:')
        self.assertEqual(y.canonical_prefix(), ':File:')
        self.assertEqual(y.custom_prefix(), u':ملف:')
예제 #18
0
    def testNamespaceToString(self):
        ns = Namespace.builtin_namespaces(use_image_name=False)

        self.assertEqual(str(ns[0]), ':')
        self.assertEqual(str(ns[1]), 'Talk:')
        self.assertEqual(str(ns[6]), ':File:')

        self.assertEqual(unicode(ns[0]), u':')
        self.assertEqual(unicode(ns[1]), u'Talk:')
        self.assertEqual(unicode(ns[6]), u':File:')

        kwargs = {u'case': u'first-letter'}
        y = Namespace(id=6, custom_name=u'ملف', canonical_name=u'File',
                      aliases=[u'Image', u'Immagine'], **kwargs)

        self.assertEqual(str(y), ':File:')
        if sys.version_info[0] <= 2:
            self.assertEqual(unicode(y), u':ملف:')
        self.assertEqual(y.canonical_prefix(), ':File:')
        self.assertEqual(y.custom_prefix(), u':ملف:')
예제 #19
0
    def test_repr(self):
        a = Namespace(id=0, canonical_name=u'Foo')
        s = repr(a)
        r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[])" \
            % (unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        a.defaultcontentmodel = 'bar'
        s = repr(a)
        r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], defaultcontentmodel='bar')" \
            % (unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        a.case = 'upper'
        s = repr(a)
        r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], case='upper', defaultcontentmodel='bar')" \
            % (unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        b = eval(repr(a))
        self.assertEqual(a, b)
예제 #20
0
    def test_repr(self):
        a = Namespace(id=0, canonical_name=u'Foo')
        s = repr(a)
        r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[])" \
            % (unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        a.defaultcontentmodel = 'bar'
        s = repr(a)
        r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], defaultcontentmodel='bar')" \
            % (unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        a.case = 'upper'
        s = repr(a)
        r = "Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], case='upper', defaultcontentmodel='bar')" \
            % (unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        b = eval(repr(a))
        self.assertEqual(a, b)
예제 #21
0
    def testNamespaceTypes(self):
        """Test cases for methods manipulating namespace names."""
        ns = Namespace.builtin_namespaces(use_image_name=False)

        self.assertIsInstance(ns, dict)
        self.assertTrue(all(x in ns for x in range(0, 16)))

        self.assertTrue(all(isinstance(key, int)
                            for key in ns))
        self.assertTrue(all(isinstance(val, Iterable)
                            for val in ns.values()))
        self.assertTrue(all(isinstance(name, basestring)
                            for val in ns.values()
                            for name in val))

        self.assertTrue(all(isinstance(Namespace.lookup_name(b, ns), Namespace)
                            for b in self.builtin_ids))

        self.assertTrue(all(Namespace.lookup_name(b, ns).id == self.all_builtin_ids[b]
                            for b in self.all_builtin_ids))

        ns = Namespace.builtin_namespaces(use_image_name=True)

        self.assertTrue(all(isinstance(Namespace.lookup_name(b, ns), Namespace)
                            for b in self.builtin_ids))

        self.assertTrue(all(Namespace.lookup_name(b, ns).id == self.all_builtin_ids[b]
                            for b in self.all_builtin_ids))

        # Use a namespace object as a dict key
        self.assertEqual(ns[ns[6]], ns[6])
예제 #22
0
    def testNamespaceTypes(self):
        """Test cases for methods manipulating namespace names."""
        ns = Namespace.builtin_namespaces(use_image_name=False)

        self.assertIsInstance(ns, dict)
        self.assertTrue(all(x in ns for x in range(0, 16)))

        self.assertTrue(all(isinstance(key, int)
                            for key in ns))
        self.assertTrue(all(isinstance(val, Iterable)
                            for val in ns.values()))
        self.assertTrue(all(isinstance(name, basestring)
                            for val in ns.values()
                            for name in val))

        self.assertTrue(all(isinstance(Namespace.lookup_name(b, ns), Namespace)
                            for b in self.builtin_ids))

        self.assertTrue(all(Namespace.lookup_name(b, ns).id == self.all_builtin_ids[b]
                            for b in self.all_builtin_ids))

        ns = Namespace.builtin_namespaces(use_image_name=True)

        self.assertTrue(all(isinstance(Namespace.lookup_name(b, ns), Namespace)
                            for b in self.builtin_ids))

        self.assertTrue(all(Namespace.lookup_name(b, ns).id == self.all_builtin_ids[b]
                            for b in self.all_builtin_ids))

        # Use a namespace object as a dict key
        self.assertEqual(ns[ns[6]], ns[6])
예제 #23
0
    def test_set(self):
        """Test converting sequence of Namespace to a set."""
        namespaces = Namespace.builtin_namespaces()

        self.assertTrue(all(isinstance(x, int) for x in namespaces))
        self.assertTrue(all(isinstance(x, int) for x in namespaces.keys()))
        self.assertTrue(all(isinstance(x, Namespace)
                            for x in namespaces.values()))

        namespaces_set = set(namespaces)

        self.assertLength(namespaces, namespaces_set)
        self.assertTrue(all(isinstance(x, int) for x in namespaces_set))
예제 #24
0
    def __init__(self, code, fam, user, sysop):
        """Constructor."""
        super(DryDataSite, self).__init__(code, fam, user, sysop)

        self._namespaces[0].defaultcontentmodel = 'wikibase-item'

        self._namespaces.update({
            120:
            Namespace(id=120,
                      case='first-letter',
                      canonical_name='Property',
                      defaultcontentmodel='wikibase-property')
        })
예제 #25
0
 def __init__(self, code, fam, user, sysop):
     """Constructor."""
     super(DrySite, self).__init__(code, fam, user, sysop)
     self._userinfo = pywikibot.tools.EMPTY_DEFAULT
     self._paraminfo = DryParamInfo()
     self._siteinfo = DummySiteinfo({})
     self._siteinfo._cache['lang'] = (code, True)
     self._siteinfo._cache['case'] = (
         'case-sensitive' if self.family.name == 'wiktionary' else
         'first-letter', True)
     self._namespaces = SelfCallDict(
         Namespace.builtin_namespaces(
             case=self.siteinfo['case']))
예제 #26
0
 def testNamespaceNameCase(self):
     """Namespace names are always case-insensitive."""
     kwargs = {'case': 'first-letter'}
     y = Namespace(id=6, custom_name='dummy', canonical_name='File',
                   aliases=['Image', 'Immagine'], **kwargs)
     self.assertIn('dummy', y)
     self.assertIn('Dummy', y)
     self.assertIn('file', y)
     self.assertIn('File', y)
     self.assertIn('image', y)
     self.assertIn('Image', y)
     self.assertIn('immagine', y)
     self.assertIn('Immagine', y)
예제 #27
0
    def test_set(self):
        """Test converting sequence of Namespace to a set."""
        namespaces = Namespace.builtin_namespaces(use_image_name=False)

        self.assertTrue(all(isinstance(x, int) for x in namespaces))
        self.assertTrue(all(isinstance(x, int) for x in namespaces.keys()))
        self.assertTrue(all(isinstance(x, Namespace)
                            for x in namespaces.values()))

        namespaces_set = set(namespaces)

        self.assertEqual(len(namespaces), len(namespaces_set))
        self.assertTrue(all(isinstance(x, int) for x in namespaces_set))
예제 #28
0
    def test_set(self):
        """Test converting sequence of Namespace to a set."""
        namespaces = Namespace.builtin_namespaces(use_image_name=False)

        self.assertTrue(all(isinstance(x, int) for x in namespaces))
        self.assertTrue(all(isinstance(x, int) for x in namespaces.keys()))
        self.assertTrue(
            all(isinstance(x, Namespace) for x in namespaces.values()))

        namespaces_set = set(namespaces)

        self.assertEqual(len(namespaces), len(namespaces_set))
        self.assertTrue(all(isinstance(x, int) for x in namespaces_set))
예제 #29
0
    def testNamespaceTypes(self):
        """Test cases for methods manipulating Namespace names."""
        ns = Namespace.builtin_namespaces()

        self.assertIsInstance(ns, dict)
        self.assertTrue(all(x in ns for x in range(0, 16)))

        self.assertTrue(all(isinstance(key, int) for key in ns))
        self.assertTrue(all(isinstance(val, Iterable) for val in ns.values()))
        self.assertTrue(
            all(isinstance(name, str) for val in ns.values() for name in val))

        # Use a namespace object as a dict key
        self.assertEqual(ns[ns[6]], ns[6])
예제 #30
0
    def test_repr(self):
        """Test Namespace.__repr__."""
        a = Namespace(id=0, canonical_name=u'Foo')
        s = repr(a)
        r = "Namespace(id=0, custom_name={0!r}, canonical_name={1!r}, aliases=[])".format(unicode('Foo'), unicode('Foo'))
        self.assertEqual(s, r)

        a.defaultcontentmodel = 'bar'
        s = repr(a)
        r = ('Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], '
             'defaultcontentmodel=%r)' %
             (unicode('Foo'), unicode('Foo'), unicode('bar')))
        self.assertEqual(s, r)

        a.case = 'upper'
        s = repr(a)
        r = ('Namespace(id=0, custom_name=%r, canonical_name=%r, aliases=[], '
             'case=%r, defaultcontentmodel=%r)' %
             (unicode('Foo'), unicode('Foo'), unicode('upper'), unicode('bar')))
        self.assertEqual(s, r)

        b = eval(repr(a))
        self.assertEqual(a, b)
예제 #31
0
        class DrySite(pywikibot.site.DataSite):
            _namespaces = {
                90: Namespace(id=90,
                              canonical_name='Item',
                              defaultcontentmodel='wikibase-item'),
                92: Namespace(id=92,
                              canonical_name='Prop',
                              defaultcontentmodel='wikibase-property')
            }

            __init__ = lambda *args: None
            code = 'test'
            family = lambda: None
            family.name = 'test'
            _logged_in_as = None
            _siteinfo = {'case': 'first-letter'}
            _item_namespace = None
            _property_namespace = None

            def encoding(self):
                return 'utf-8'

            def encodings(self):
                return []
예제 #32
0
    def testNamespaceConstructor(self):
        kwargs = {u'case': u'first-letter'}
        y = Namespace(id=6, custom_name=u'dummy', canonical_name=u'File',
                      aliases=[u'Image', u'Immagine'], **kwargs)

        self.assertEqual(y.id, 6)
        self.assertEqual(y.custom_name, u'dummy')
        self.assertEqual(y.canonical_name, u'File')

        self.assertNotEqual(y.custom_name, u'Dummy')
        self.assertNotEqual(y.canonical_name, u'file')

        self.assertIn(u'Image', y.aliases)
        self.assertIn(u'Immagine', y.aliases)

        self.assertEqual(len(y), 4)
        self.assertEqual(list(y), ['dummy', u'File', u'Image', u'Immagine'])
        self.assertEqual(y.case, u'first-letter')
예제 #33
0
    def testNamespaceConstructor(self):
        """Test Namespace constructor."""
        kwargs = {'case': 'first-letter'}
        y = Namespace(id=6, custom_name='dummy', canonical_name='File',
                      aliases=['Image', 'Immagine'], **kwargs)

        self.assertEqual(y.id, 6)
        self.assertEqual(y.custom_name, 'dummy')
        self.assertEqual(y.canonical_name, 'File')

        self.assertNotEqual(y.custom_name, 'Dummy')
        self.assertNotEqual(y.canonical_name, 'file')

        self.assertIn('Image', y.aliases)
        self.assertIn('Immagine', y.aliases)

        self.assertLength(y, 4)
        self.assertEqual(list(y), ['dummy', 'File', 'Image', 'Immagine'])
        self.assertEqual(y.case, 'first-letter')
예제 #34
0
    def test_resolve_equal(self):
        """Test Namespace.resolve success."""
        namespaces = Namespace.builtin_namespaces(use_image_name=False)
        main_ns = namespaces[0]
        file_ns = namespaces[6]
        special_ns = namespaces[-1]

        self.assertEqual(Namespace.resolve([6]), [file_ns])
        self.assertEqual(Namespace.resolve(['File']), [file_ns])
        self.assertEqual(Namespace.resolve(['6']), [file_ns])
        self.assertEqual(Namespace.resolve([file_ns]), [file_ns])

        self.assertEqual(Namespace.resolve([file_ns, special_ns]),
                         [file_ns, special_ns])
        self.assertEqual(Namespace.resolve([file_ns, file_ns]),
                         [file_ns, file_ns])

        self.assertEqual(Namespace.resolve(6), [file_ns])
        self.assertEqual(Namespace.resolve('File'), [file_ns])
        self.assertEqual(Namespace.resolve('6'), [file_ns])
        self.assertEqual(Namespace.resolve(file_ns), [file_ns])

        self.assertEqual(Namespace.resolve(0), [main_ns])
        self.assertEqual(Namespace.resolve('0'), [main_ns])

        self.assertEqual(Namespace.resolve(-1), [special_ns])
        self.assertEqual(Namespace.resolve('-1'), [special_ns])

        self.assertEqual(Namespace.resolve('File:'), [file_ns])
        self.assertEqual(Namespace.resolve(':File'), [file_ns])
        self.assertEqual(Namespace.resolve(':File:'), [file_ns])

        self.assertEqual(Namespace.resolve('Image:'), [file_ns])
        self.assertEqual(Namespace.resolve(':Image'), [file_ns])
        self.assertEqual(Namespace.resolve(':Image:'), [file_ns])
예제 #35
0
    def testNamespaceNormalizeName(self):
        """Test Namespace.normalize_name."""
        self.assertEqual(Namespace.normalize_name(u'File'), u'File')
        self.assertEqual(Namespace.normalize_name(u':File'), u'File')
        self.assertEqual(Namespace.normalize_name(u'File:'), u'File')
        self.assertEqual(Namespace.normalize_name(u':File:'), u'File')

        self.assertEqual(Namespace.normalize_name(u''), u'')

        self.assertEqual(Namespace.normalize_name(u':'), False)
        self.assertEqual(Namespace.normalize_name(u'::'), False)
        self.assertEqual(Namespace.normalize_name(u':::'), False)
        self.assertEqual(Namespace.normalize_name(u':File::'), False)
        self.assertEqual(Namespace.normalize_name(u'::File:'), False)
        self.assertEqual(Namespace.normalize_name(u'::File::'), False)
예제 #36
0
 def _build_namespaces(self):
     return Namespace.builtin_namespaces(case=self.siteinfo['case'])
예제 #37
0
    def test_resolve_equal(self):
        """Test Namespace.resolve success."""
        namespaces = Namespace.builtin_namespaces(use_image_name=False)
        main_ns = namespaces[0]
        file_ns = namespaces[6]
        special_ns = namespaces[-1]

        self.assertEqual(Namespace.resolve([6]), [file_ns])
        self.assertEqual(Namespace.resolve(['File']), [file_ns])
        self.assertEqual(Namespace.resolve(['6']), [file_ns])
        self.assertEqual(Namespace.resolve([file_ns]), [file_ns])

        self.assertEqual(Namespace.resolve([file_ns, special_ns]),
                         [file_ns, special_ns])
        self.assertEqual(Namespace.resolve([file_ns, file_ns]),
                         [file_ns, file_ns])

        self.assertEqual(Namespace.resolve(6), [file_ns])
        self.assertEqual(Namespace.resolve('File'), [file_ns])
        self.assertEqual(Namespace.resolve('6'), [file_ns])
        self.assertEqual(Namespace.resolve(file_ns), [file_ns])

        self.assertEqual(Namespace.resolve(0), [main_ns])
        self.assertEqual(Namespace.resolve('0'), [main_ns])

        self.assertEqual(Namespace.resolve(-1), [special_ns])
        self.assertEqual(Namespace.resolve('-1'), [special_ns])

        self.assertEqual(Namespace.resolve('File:'), [file_ns])
        self.assertEqual(Namespace.resolve(':File'), [file_ns])
        self.assertEqual(Namespace.resolve(':File:'), [file_ns])

        self.assertEqual(Namespace.resolve('Image:'), [file_ns])
        self.assertEqual(Namespace.resolve(':Image'), [file_ns])
        self.assertEqual(Namespace.resolve(':Image:'), [file_ns])
예제 #38
0
    def testNamespaceNormalizeName(self):
        self.assertEqual(Namespace.normalize_name(u'File'), u'File')
        self.assertEqual(Namespace.normalize_name(u':File'), u'File')
        self.assertEqual(Namespace.normalize_name(u'File:'), u'File')
        self.assertEqual(Namespace.normalize_name(u':File:'), u'File')

        self.assertEqual(Namespace.normalize_name(u''), u'')

        self.assertEqual(Namespace.normalize_name(u':'), False)
        self.assertEqual(Namespace.normalize_name(u'::'), False)
        self.assertEqual(Namespace.normalize_name(u':::'), False)
        self.assertEqual(Namespace.normalize_name(u':File::'), False)
        self.assertEqual(Namespace.normalize_name(u'::File:'), False)
        self.assertEqual(Namespace.normalize_name(u'::File::'), False)
예제 #39
0
    def testNamespaceNormalizeName(self):
        """Test Namespace.normalize_name."""
        self.assertEqual(Namespace.normalize_name('File'), 'File')
        self.assertEqual(Namespace.normalize_name(':File'), 'File')
        self.assertEqual(Namespace.normalize_name('File:'), 'File')
        self.assertEqual(Namespace.normalize_name(':File:'), 'File')

        self.assertEqual(Namespace.normalize_name(''), '')

        self.assertEqual(Namespace.normalize_name(':'), False)
        self.assertEqual(Namespace.normalize_name('::'), False)
        self.assertEqual(Namespace.normalize_name(':::'), False)
        self.assertEqual(Namespace.normalize_name(':File::'), False)
        self.assertEqual(Namespace.normalize_name('::File:'), False)
        self.assertEqual(Namespace.normalize_name('::File::'), False)
예제 #40
0
def builtin_NamespacesDict():
    """Return a NamespacesDict of the builtin namespaces."""
    return NamespacesDict(Namespace.builtin_namespaces())
예제 #41
0
def builtin_NamespacesDict():
    """Return a NamespacesDict of the builtin namespaces."""
    return NamespacesDict(Namespace.builtin_namespaces())
예제 #42
0
    def test_resolve(self):
        """Test Namespace.resolve."""
        namespaces = Namespace.builtin_namespaces(use_image_name=False)
        main_ns = namespaces[0]
        file_ns = namespaces[6]
        special_ns = namespaces[-1]

        self.assertEqual(Namespace.resolve([6]), [file_ns])
        self.assertEqual(Namespace.resolve(['File']), [file_ns])
        self.assertEqual(Namespace.resolve(['6']), [file_ns])
        self.assertEqual(Namespace.resolve([file_ns]), [file_ns])

        self.assertEqual(Namespace.resolve([file_ns, special_ns]),
                         [file_ns, special_ns])
        self.assertEqual(Namespace.resolve([file_ns, file_ns]),
                         [file_ns, file_ns])

        self.assertEqual(Namespace.resolve(6), [file_ns])
        self.assertEqual(Namespace.resolve('File'), [file_ns])
        self.assertEqual(Namespace.resolve('6'), [file_ns])
        self.assertEqual(Namespace.resolve(file_ns), [file_ns])

        self.assertEqual(Namespace.resolve(0), [main_ns])
        self.assertEqual(Namespace.resolve('0'), [main_ns])

        self.assertEqual(Namespace.resolve(-1), [special_ns])
        self.assertEqual(Namespace.resolve('-1'), [special_ns])

        self.assertEqual(Namespace.resolve('File:'), [file_ns])
        self.assertEqual(Namespace.resolve(':File'), [file_ns])
        self.assertEqual(Namespace.resolve(':File:'), [file_ns])

        self.assertEqual(Namespace.resolve('Image:'), [file_ns])
        self.assertEqual(Namespace.resolve(':Image'), [file_ns])
        self.assertEqual(Namespace.resolve(':Image:'), [file_ns])

        self.assertRaises(TypeError, Namespace.resolve, [True])
        self.assertRaises(TypeError, Namespace.resolve, [False])
        self.assertRaises(TypeError, Namespace.resolve, [None])
        self.assertRaises(TypeError, Namespace.resolve, True)
        self.assertRaises(TypeError, Namespace.resolve, False)
        self.assertRaises(TypeError, Namespace.resolve, None)

        self.assertRaises(KeyError, Namespace.resolve, -10)
        self.assertRaises(KeyError, Namespace.resolve, '-10')
        self.assertRaises(KeyError, Namespace.resolve, 'foo')
        self.assertRaises(KeyError, Namespace.resolve, ['foo'])

        self.assertRaisesRegex(KeyError,
                               r'Namespace identifier\(s\) not recognised: -10',
                               Namespace.resolve, [-10, 0])
        self.assertRaisesRegex(KeyError,
                               r'Namespace identifier\(s\) not recognised: foo',
                               Namespace.resolve, [0, 'foo'])
        self.assertRaisesRegex(KeyError,
                               r'Namespace identifier\(s\) not recognised: -10,-11',
                               Namespace.resolve, [-10, 0, -11])
예제 #43
0
    def test_resolve(self):
        """Test Namespace.resolve."""
        namespaces = Namespace.builtin_namespaces(use_image_name=False)
        main_ns = namespaces[0]
        file_ns = namespaces[6]
        special_ns = namespaces[-1]

        self.assertEqual(Namespace.resolve([6]), [file_ns])
        self.assertEqual(Namespace.resolve(['File']), [file_ns])
        self.assertEqual(Namespace.resolve(['6']), [file_ns])
        self.assertEqual(Namespace.resolve([file_ns]), [file_ns])

        self.assertEqual(Namespace.resolve([file_ns, special_ns]),
                                           [file_ns, special_ns])
        self.assertEqual(Namespace.resolve([file_ns, file_ns]),
                                           [file_ns, file_ns])

        self.assertEqual(Namespace.resolve(6), [file_ns])
        self.assertEqual(Namespace.resolve('File'), [file_ns])
        self.assertEqual(Namespace.resolve('6'), [file_ns])
        self.assertEqual(Namespace.resolve(file_ns), [file_ns])

        self.assertEqual(Namespace.resolve(0), [main_ns])
        self.assertEqual(Namespace.resolve('0'), [main_ns])

        self.assertEqual(Namespace.resolve(-1), [special_ns])
        self.assertEqual(Namespace.resolve('-1'), [special_ns])

        self.assertEqual(Namespace.resolve('File:'), [file_ns])
        self.assertEqual(Namespace.resolve(':File'), [file_ns])
        self.assertEqual(Namespace.resolve(':File:'), [file_ns])

        self.assertEqual(Namespace.resolve('Image:'), [file_ns])
        self.assertEqual(Namespace.resolve(':Image'), [file_ns])
        self.assertEqual(Namespace.resolve(':Image:'), [file_ns])

        self.assertRaises(TypeError, Namespace.resolve, [True])
        self.assertRaises(TypeError, Namespace.resolve, [False])
        self.assertRaises(TypeError, Namespace.resolve, [None])
        self.assertRaises(TypeError, Namespace.resolve, True)
        self.assertRaises(TypeError, Namespace.resolve, False)
        self.assertRaises(TypeError, Namespace.resolve, None)

        self.assertRaises(KeyError, Namespace.resolve, -10)
        self.assertRaises(KeyError, Namespace.resolve, '-10')
        self.assertRaises(KeyError, Namespace.resolve, 'foo')
        self.assertRaises(KeyError, Namespace.resolve, ['foo'])

        self.assertRaisesRegex(KeyError,
                               r'Namespace identifier\(s\) not recognised: -10',
                               Namespace.resolve, [-10, 0])
        self.assertRaisesRegex(KeyError,
                               r'Namespace identifier\(s\) not recognised: foo',
                               Namespace.resolve, [0, 'foo'])
        self.assertRaisesRegex(KeyError,
                               r'Namespace identifier\(s\) not recognised: -10,-11',
                               Namespace.resolve, [-10, 0, -11])