コード例 #1
0
 def test_filelike_cmp_multiple_time(self):
     # make sure filepointers are reset when we use the same
     # file-like object several times (as often happens in loops).
     p1 = os.path.join(self.workdir, b'p1')
     open(p1, 'w').write(b'foo')
     filelike1 = StringIO(b'foo')
     filelike2 = StringIO(b'bar')
     assert filelike_cmp(p1, filelike1) == True
     assert filelike_cmp(p1, filelike2) == False
     assert filelike_cmp(p1, filelike1) == True
     assert filelike_cmp(p1, filelike2) == False
コード例 #2
0
 def test_filelike_cmp_multiple_time(self, tmpdir):
     # make sure filepointers are reset when we use the same
     # file-like object several times (as often happens in loops).
     tmpdir.join('p1').write('foo')
     p1 = str(tmpdir.join('p1'))
     filelike1 = StringIO('foo')
     filelike2 = StringIO('bar')
     assert filelike_cmp(p1, filelike1) is True
     assert filelike_cmp(p1, filelike2) is False
     assert filelike_cmp(p1, filelike1) is True
     assert filelike_cmp(p1, filelike2) is False
コード例 #3
0
 def test_filelike_cmp(self):
     assert filelike_cmp(
         StringIO(b'asd'), StringIO(b'qwe')) is False
     assert filelike_cmp(
         StringIO(b'asd'), StringIO(b'asd')) is True
     p1 = os.path.join(self.workdir, b'p1')
     p2 = os.path.join(self.workdir, b'p2')
     p3 = os.path.join(self.workdir, b'p3')
     open(p1, 'w').write(b'asd')
     open(p2, 'w').write(b'qwe')
     open(p3, 'w').write(b'asd')
     assert filelike_cmp(p1, p2) is False
     assert filelike_cmp(p1, p3) is True
     assert filelike_cmp(p1, StringIO(b'asd')) is True
     assert filelike_cmp(StringIO(b'qwe'), p2) is True
コード例 #4
0
 def test_filelike_cmp(self, tmpdir):
     assert filelike_cmp(
         StringIO('asd'), StringIO('qwe')) is False
     assert filelike_cmp(
         StringIO('asd'), StringIO('asd')) is True
     tmpdir.join('p1').write('asd')
     tmpdir.join('p2').write('qwe')
     tmpdir.join('p3').write('asd')
     p1 = str(tmpdir.join('p1'))
     p2 = str(tmpdir.join('p2'))
     p3 = str(tmpdir.join('p3'))
     assert filelike_cmp(p1, p2) is False
     assert filelike_cmp(p1, p3) is True
     assert filelike_cmp(p1, StringIO('asd')) is True
     assert filelike_cmp(StringIO('qwe'), p2) is True
コード例 #5
0
 def test_filelike_cmp_w_bytes(self, tmpdir):
     # we can compare bytestreams
     assert filelike_cmp(
         BytesIO(b'asd'), BytesIO(b'qwe')) is False
     assert filelike_cmp(
         BytesIO(b'asd'), BytesIO(b'asd')) is True
     tmpdir.join('p1').write('asd')
     tmpdir.join('p2').write('qwe')
     tmpdir.join('p3').write('asd')
     p1 = str(tmpdir.join('p1'))
     p2 = str(tmpdir.join('p2'))
     p3 = str(tmpdir.join('p3'))
     assert filelike_cmp(p1, p2) is False
     assert filelike_cmp(p1, p3) is True
     assert filelike_cmp(p1, BytesIO(b'asd')) is True
     assert filelike_cmp(BytesIO(b'qwe'), p2) is True
コード例 #6
0
ファイル: cachemanager.py プロジェクト: ulif/ulif.openoffice
    def get_stored_repr_num(self, src_num, repr_key):
        """Find a representation number for source number `src_num`.

        If for source number `src_num` a representation with key
        `repr_key` is stored already in bucket, the number of the
        respective representation will be returned.

        If no such key can be found for the given source, you will get
        ``None``.
        """
        keydir = os.path.join(self.keysdir, str(src_num))
        if not os.path.isdir(keydir):
            return None
        for name in os.listdir(keydir):
            keypath = os.path.join(keydir, name)
            f1 = open(keypath, 'rb')
            f2 = repr_key
            if isinstance(f2, str):
                f2 = StringIO(repr_key)
            if filelike_cmp(f1, f2):
                return int(name.split('.')[0])
        return None
コード例 #7
0
ファイル: cachemanager.py プロジェクト: ulif/ulif.openoffice
    def get_stored_repr_num(self, src_num, repr_key):
        """Find a representation number for source number `src_num`.

        If for source number `src_num` a representation with key
        `repr_key` is stored already in bucket, the number of the
        respective representation will be returned.

        If no such key can be found for the given source, you will get
        ``None``.
        """
        keydir = os.path.join(self.keysdir, str(src_num))
        if not os.path.isdir(keydir):
            return None
        for name in os.listdir(keydir):
            keypath = os.path.join(keydir, name)
            f1 = open(keypath, 'rb')
            f2 = repr_key
            if isinstance(f2, str):
                f2 = StringIO(repr_key)
            if filelike_cmp(f1, f2):
                return int(name.split('.')[0])
        return None