コード例 #1
0
    def test_parse_file_source(self):
        d = b''.join([self.hm, self.hg])
        add = b"a:17:32:%d\n%s" % (len(d), d)
        sub = b"s:18:32:%d\n%s" % (len(d), d)

        adds = [
            Chunk(chunk_type='a',
                  number=17,
                  hashes=set([self.hg, self.hm]),
                  hash_size=32)
        ]
        subs = [
            Chunk(chunk_type='s',
                  number=18,
                  hashes=set([self.hg, self.hm]),
                  hash_size=32)
        ]

        self.assertEqual(parse_file_source(io.BytesIO(add)),
                         ChunkList(add_chunks=adds))
        self.assertEqual(parse_file_source(io.BytesIO(sub)),
                         ChunkList(sub_chunks=subs))
        # Both adds and subs with a spurious newline in between
        both = b"%s\n%s" % (add, sub)
        self.assertEqual(parse_file_source(io.BytesIO(both)),
                         ChunkList(add_chunks=adds, sub_chunks=subs))
コード例 #2
0
ファイル: test_parse.py プロジェクト: rtilder/shavar
    def test_parse_file_source(self):
        d = ''.join([self.hm, self.hg])
        add = "a:17:32:%d\n%s" % (len(d), d)
        sub = "s:18:32:%d\n%s" % (len(d), d)

        adds = [Chunk(chunk_type='a', number=17, hashes=set([self.hg,
                                                             self.hm]),
                      hash_size=32)]
        subs = [Chunk(chunk_type='s', number=18, hashes=set([self.hg,
                                                             self.hm]),
                      hash_size=32)]

        self.assertEqual(parse_file_source(StringIO.StringIO(add)),
                         ChunkList(add_chunks=adds))
        self.assertEqual(parse_file_source(StringIO.StringIO(sub)),
                         ChunkList(sub_chunks=subs))
        # Both adds and subs with a spurious newline in between
        both = "%s\n%s" % (add, sub)
        self.assertEqual(parse_file_source(StringIO.StringIO(both)),
                         ChunkList(add_chunks=adds, sub_chunks=subs))
コード例 #3
0
ファイル: test_parse.py プロジェクト: rtilder/shavar
    def test_parse_file_source_delta(self):
        def chunkit(n, typ, *urls):
            return Chunk(number=n, chunk_type=typ,
                         hashes=[hashlib.sha256(u).digest() for u in urls])

        result = ChunkList(add_chunks=[chunkit(1, 'a',
                                               'https://www.mozilla.org/',
                                               'https://www.google.com/'),
                                       chunkit(2, 'a', 'https://github.com/',
                                               'http://www.python.org/'),
                                       chunkit(4, 'a',
                                               'http://www.haskell.org/',
                                               'https://www.mozilla.com/'),
                                       chunkit(5, 'a', 'http://www.erlang.org',
                                               'http://golang.org/')],
                           sub_chunks=[chunkit(3, 's',
                                               'https://github.com/'),
                                       chunkit(6, 's',
                                               'http://golang.org')])
        p = parse_file_source(open(test_file('delta_chunk_source')))
        self.assertEqual(p, result)
コード例 #4
0
 def test_parse_file_source_delta(self):
     p = parse_file_source(open(test_file('delta_chunk_source'), 'rb'))
     self.assertEqual(p, DELTA_RESULT)