Пример #1
0
    def test_generate_path_leaves(self):
        data = open(DATA).read()
        nodes, bits = PathTree._unpack_data(data)
        ret = PathTree._generate_path_leaves(GhettoBitStream(bits))

        self.assertEqual(len(ret), 4)
        for node in ret:
            self.assertTrue(isinstance(node, HuffmanNode))
Пример #2
0
 def test_match_variable(self):
     tree = {"foo": [{"$releasever": [{"bar": [{PATH_END: None}]}]}]}
     data = open(DATA).read()
     pt = PathTree(data)
     # just swap out the pre-cooked data with out with
     pt.path_tree = tree
     self.assertTrue(pt.match_path("/foo/path/bar"))
     self.assertFalse(pt.match_path("/foo/path/abc"))
Пример #3
0
 def test_unpack_data(self):
     data = open(DATA).read()
     nodes, bits = PathTree._unpack_data(data)
     self.assertEqual(len(nodes), 6)
     # first node always gets weight of 1
     self.assertEqual(nodes[0].weight, 1)
     self.assertEqual(nodes[0].value, "never")
     self.assertEqual(nodes[5].weight, 6)
     self.assertEqual(nodes[5].value, "")
     self.assertEqual(len(bits), 6)
Пример #4
0
 def test_match_path(self):
     data = open(DATA).read()
     pt = PathTree(data)
     self.assertTrue(pt.match_path("/foo/path"))
     self.assertTrue(pt.match_path("/foo/path/"))
     # the '2' should match against "$releasever"
     self.assertTrue(pt.match_path("/foo/path/always/2"))
     self.assertTrue(pt.match_path("/foo/path/bar"))
     self.assertTrue(pt.match_path("/foo/path/bar/a/b/c"))
     self.assertFalse(pt.match_path("/foo"))
     self.assertFalse(pt.match_path("/bar"))
Пример #5
0
 def test_generate_path_tree(self):
     data = open(DATA).read()
     pt = PathTree(data).path_tree
     self.assertTrue("foo" in pt)
     self.assertEqual(len(pt.keys()), 1)
Пример #6
0
 def test_get_node_count_big(self):
     bs = GhettoBitStream([])
     # count bigger than 127, need next 2 bytes to represent it
     bs.bytes = deque([130, 1, 17])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 273)
Пример #7
0
 def test_get_node_count_medium(self):
     bs = GhettoBitStream([])
     # count bigger than 127, only need 1 byte to represent it
     bs.bytes = deque([129, 150])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 150)
Пример #8
0
 def test_get_node_count_small(self):
     bs = GhettoBitStream([])
     bs.bytes = deque([6])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 6)
Пример #9
0
 def test_get_leaf_from_dict(self):
     codes = {"1010": "abc"}
     bitstream = "10101111110000"
     ret = PathTree._get_leaf_from_dict(codes, bitstream)
     self.assertEqual(ret, "abc")