Example #1
0
    def test_trie_traversal(self):
        trie = SourceRootTrie(SourceRootFactory({}))
        trie.add_pattern('foo1/bar1/baz1')
        trie.add_pattern('foo1/bar1/baz2/qux')
        trie.add_pattern('foo1/bar2/baz1')
        trie.add_pattern('foo1/bar2/baz2')
        trie.add_pattern('foo2/bar1')
        trie.add_fixed('fixed1/bar1', ['lang1'], SOURCE)
        trie.add_fixed('fixed2/bar2', ['lang2'], TEST)

        # Test raw traversal.
        self.assertEqual(
            {('baz1', (), UNKNOWN), ('baz2/qux', (), UNKNOWN)},
            set(trie._root.children['foo1'].children['bar1'].subpatterns()))

        self.assertEqual(
            {('bar1/baz1', (), UNKNOWN), ('bar1/baz2/qux', (), UNKNOWN),
             ('bar2/baz1', (), UNKNOWN), ('bar2/baz2', (), UNKNOWN)},
            set(trie._root.children['foo1'].subpatterns()))

        self.assertEqual(
            {('foo1/bar1/baz1', (), UNKNOWN),
             ('foo1/bar1/baz2/qux', (), UNKNOWN),
             ('foo1/bar2/baz1', (), UNKNOWN), ('foo1/bar2/baz2', (), UNKNOWN),
             ('foo2/bar1', (), UNKNOWN),
             ('^/fixed1/bar1', ('lang1', ), SOURCE),
             ('^/fixed2/bar2', ('lang2', ), TEST)},
            set(trie._root.subpatterns()))

        # Test the fixed() method.
        self.assertEqual(
            {('fixed1/bar1', ('lang1', ), SOURCE),
             ('fixed2/bar2', ('lang2', ), TEST)}, set(trie.fixed()))
Example #2
0
  def test_trie_traversal(self):
    trie = SourceRootTrie(SourceRootFactory({}))
    trie.add_pattern('foo1/bar1/baz1')
    trie.add_pattern('foo1/bar1/baz2/qux')
    trie.add_pattern('foo1/bar2/baz1')
    trie.add_pattern('foo1/bar2/baz2')
    trie.add_pattern('foo2/bar1')
    trie.add_fixed('fixed1/bar1', ['lang1'])
    trie.add_fixed('fixed2/bar2', ['lang2'])

    # Test raw traversal.
    self.assertEquals([('baz1', ()), ('baz2/qux', ())],
                      list(trie._root.children['foo1'].children['bar1'].subpatterns()))

    self.assertEquals([('bar1/baz1', ()), ('bar1/baz2/qux', ()),
                       ('bar2/baz1', ()), ('bar2/baz2', ())],
                      list(trie._root.children['foo1'].subpatterns()))

    self.assertEquals([('foo1/bar1/baz1', ()), ('foo1/bar1/baz2/qux', ()),
                       ('foo1/bar2/baz1', ()), ('foo1/bar2/baz2', ()), ('foo2/bar1', ()),
                       ('^/fixed1/bar1', ('lang1',)), ('^/fixed2/bar2', ('lang2',))],
                      list(trie._root.subpatterns()))

    # Test the fixed() method.
    self.assertEquals([('fixed1/bar1', ('lang1',)), ('fixed2/bar2', ('lang2',))],
                      trie.fixed())
Example #3
0
  def test_trie_traversal(self):
    trie = SourceRootTrie(SourceRootFactory({}))
    trie.add_pattern('foo1/bar1/baz1')
    trie.add_pattern('foo1/bar1/baz2/qux')
    trie.add_pattern('foo1/bar2/baz1')
    trie.add_pattern('foo1/bar2/baz2')
    trie.add_pattern('foo2/bar1')
    trie.add_fixed('fixed1/bar1', ['lang1'], SOURCE)
    trie.add_fixed('fixed2/bar2', ['lang2'], TEST)

    # Test raw traversal.
    self.assertEqual({('baz1', (), UNKNOWN),
                      ('baz2/qux', (), UNKNOWN)},
                     set(trie._root.children['foo1'].children['bar1'].subpatterns()))

    self.assertEqual({('bar1/baz1', (), UNKNOWN),
                      ('bar1/baz2/qux', (), UNKNOWN),
                      ('bar2/baz1', (), UNKNOWN),
                      ('bar2/baz2', (), UNKNOWN)},
                     set(trie._root.children['foo1'].subpatterns()))

    self.assertEqual({('foo1/bar1/baz1', (), UNKNOWN),
                      ('foo1/bar1/baz2/qux', (), UNKNOWN),
                      ('foo1/bar2/baz1', (), UNKNOWN),
                      ('foo1/bar2/baz2', (), UNKNOWN),
                      ('foo2/bar1', (), UNKNOWN),
                      ('^/fixed1/bar1', ('lang1',), SOURCE),
                      ('^/fixed2/bar2', ('lang2',), TEST)},
                     set(trie._root.subpatterns()))

    # Test the fixed() method.
    self.assertEqual({('fixed1/bar1', ('lang1',), SOURCE),
                      ('fixed2/bar2', ('lang2',), TEST)},
                     set(trie.fixed()))
Example #4
0
    def test_trie_traversal(self):
        trie = SourceRootTrie(SourceRootFactory({}))
        trie.add_pattern("foo1/bar1/baz1")
        trie.add_pattern("foo1/bar1/baz2/qux")
        trie.add_pattern("foo1/bar2/baz1")
        trie.add_pattern("foo1/bar2/baz2")
        trie.add_pattern("foo2/bar1")
        trie.add_fixed("fixed1/bar1", ["lang1"], SOURCE)
        trie.add_fixed("fixed2/bar2", ["lang2"], TEST)

        # Test raw traversal.
        self.assertEqual(
            {("baz1", (), UNKNOWN), ("baz2/qux", (), UNKNOWN)},
            set(trie._root.children["foo1"].children["bar1"].subpatterns()),
        )

        self.assertEqual(
            {
                ("bar1/baz1", (), UNKNOWN),
                ("bar1/baz2/qux", (), UNKNOWN),
                ("bar2/baz1", (), UNKNOWN),
                ("bar2/baz2", (), UNKNOWN),
            },
            set(trie._root.children["foo1"].subpatterns()),
        )

        self.assertEqual(
            {
                ("foo1/bar1/baz1", (), UNKNOWN),
                ("foo1/bar1/baz2/qux", (), UNKNOWN),
                ("foo1/bar2/baz1", (), UNKNOWN),
                ("foo1/bar2/baz2", (), UNKNOWN),
                ("foo2/bar1", (), UNKNOWN),
                ("^/fixed1/bar1", ("lang1", ), SOURCE),
                ("^/fixed2/bar2", ("lang2", ), TEST),
            },
            set(trie._root.subpatterns()),
        )

        # Test the fixed() method.
        self.assertEqual(
            {("fixed1/bar1", ("lang1", ), SOURCE),
             ("fixed2/bar2", ("lang2", ), TEST)},
            set(trie.fixed()),
        )
Example #5
0
    def test_trie_traversal_deprecated(self):
        trie = SourceRootTrie()
        trie.add_pattern("foo1/bar1/baz1")
        trie.add_pattern("foo1/bar1/baz2/qux")
        trie.add_pattern("foo1/bar2/baz1")
        trie.add_pattern("foo1/bar2/baz2")
        trie.add_pattern("foo2/bar1")
        trie.add_fixed("fixed1/bar1")
        trie.add_fixed("fixed2/bar2")

        # Test raw traversal.
        self.assertEqual(
            {"baz1", "baz2/qux"},
            set(trie._root.children["foo1"].children["bar1"].subpatterns()),
        )

        self.assertEqual(
            {
                "bar1/baz1",
                "bar1/baz2/qux",
                "bar2/baz1",
                "bar2/baz2",
            },
            set(trie._root.children["foo1"].subpatterns()),
        )

        self.assertEqual(
            {
                "foo1/bar1/baz1",
                "foo1/bar1/baz2/qux",
                "foo1/bar2/baz1",
                "foo1/bar2/baz2",
                "foo2/bar1",
                "^/fixed1/bar1",
                "^/fixed2/bar2",
            },
            set(trie._root.subpatterns()),
        )

        # Test the fixed() method.
        self.assertEqual(
            {"fixed1/bar1", "fixed2/bar2"},
            set(trie.fixed()),
        )