예제 #1
0
 def test_symlink_roundtrip(self):
     meta = PathMeta(id='N:helloworld:123',
                     size=10,
                     checksum=b'1;o2j\x9912\xffo3ij\x01123,asdf.')
     path = self.test_path
     path._cache = SymlinkCache(path, meta=meta)
     path.cache.meta = meta
     new_meta = path.cache.meta
     path.unlink()
     msg = '\n'.join(
         [f'{k!r} {v!r} {getattr(new_meta, k)!r}' for k, v in meta.items()])
     assert meta == new_meta, msg
예제 #2
0
 def _test_symlink_roundtrip_weird(self):
     path = TestLocalPath('/tmp/testpath')  # FIXME random needed ...
     meta = PathMeta(id='N:helloworld:123',
                     size=10,
                     checksum=b'1;o2j\x9912\xffo3ij\x01123,asdf.')
     pure_symlink = PurePosixPath(path.name) / meta.as_symlink()
     path.symlink_to(pure_symlink)
     try:
         cache = SymlinkCache(path)
         new_meta = cache.meta
         msg = '\n'.join([
             f'{k!r} {v!r} {getattr(new_meta, k)!r}'
             for k, v in meta.items()
         ])
         assert meta == new_meta, msg
     finally:
         path.unlink()
예제 #3
0
 def test_metastore_roundtrip(self):
     pm = self.path.meta
     ms = pm.as_metastore(self.prefix)
     # FIXME actually write these to disk as well?
     new_pm = PathMeta.from_metastore(ms, self.prefix)
     assert new_pm == pm, '\n'.join([
         str((getattr(pm, field), getattr(new_pm, field)))
         for field in tuple()
     ])  # TODO
예제 #4
0
def mk_fldr_meta(fldr_path, ftype='collection', id=None):
    _meta = fldr_path.meta
    kwargs = {**_meta}
    kwargs[
        'id'] = id if id is not None else f'N:{ftype}:' + fldr_path.as_posix()
    meta = PathMeta(**kwargs)
    # NOTE st_mtime -> modified time of the file contents (data)
    # NOTE st_ctime -> changed time of the file status (metadata)
    # linux does not have a unified way to bet st_btime aka st_crtime which is birth time or created time
    return meta.as_xattrs(prefix='bf')
    return {
        'bf.id':
        id if id is not None else f'N:{ftype}:' + fldr_path.as_posix(),
        'bf.created':
        meta.created.isoformat().replace('.', ',')
        if meta.created is not None else None,
        'bf.updated':
        meta.updated.isoformat().replace('.', ',')
    }
예제 #5
0
 def test_xattrs_roundtrip(self):
     # TODO __kwargs ...
     pm = self.path.meta
     xattrs = pm.as_xattrs(self.prefix)
     print(xattrs)
     # FIXME actually write these to disk as well?
     new_pm = PathMeta.from_xattrs(xattrs, self.prefix)
     msg = '\n'.join(
         [f'{k!r} {v!r} {getattr(new_pm, k)!r}' for k, v in pm.items()])
     assert new_pm == pm, msg
예제 #6
0
    def test_parts_roundtrip(self):
        pmas = _PathMetaAsSymlink()
        lpm = self.path.meta
        bpm = PathMeta(id='N:helloworld:123',
                       size=10,
                       checksum=b'1;o2j\x9912\xffo3ij\x01123,asdf.')
        bads = []
        for pm in (lpm, bpm):
            symlink = pm.as_symlink()
            print(symlink)
            new_pm = pmas.from_parts(symlink.parts)
            #corrected_new_pm = PurePosixPath()
            if new_pm != pm:
                bads += [
                    '\n'.join([
                        str((getattr(pm, field), getattr(new_pm, field)))
                        for field in ('id', ) + _PathMetaAsSymlink.order
                        if not (getattr(pm, field) is getattr(new_pm, field) is
                                None)
                    ]), f'{pm.__reduce__()}\n{new_pm.__reduce__()}'
                ]

        assert not bads, '\n===========\n'.join(bads)
예제 #7
0
 def meta(self):
     return PathMeta(id=self.id)
예제 #8
0
 def metaAtTime(self, time):
     # we are cheating in order to do this
     return PathMeta(
         id=self._cache_class._remote_class.invAtTime(self, time))
예제 #9
0
        return PathMeta(id=self.id)

    def __repr__(self):
        p = self.as_path()
        return f'{self.__class__.__name__} <{self.id!r} {p!r}>'


# set up cache hierarchy
TestLocalPath._cache_class = TestCachePath
TestCachePath._local_class = TestLocalPath
TestCachePath._remote_class = TestRemotePath
TestRemotePath._cache_class = TestCachePath

# set up testing anchor (must come after the hierarchy)
TestCachePath.anchor = test_path
TestCachePath.anchor = TestCachePath(test_path, meta=PathMeta(id='0'))


class TestPathHelper:
    @classmethod
    def setUpClass(cls):
        if cls.test_base.exists():
            shutil.rmtree(cls.test_base)

        cls.test_base.mkdir()

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree(cls.test_base)

    def setUp(self, init_cache=True):
예제 #10
0
 def test___neg__(self):
     pm = PathMeta()
     assert not pm, set(pm.__dict__.values())
예제 #11
0
 def test_neg__neg__(self):
     pm = PathMeta(id='lol')
     assert pm
예제 #12
0
 def _test_getattr_size_hr(self):
     pm = PathMeta(size=1000000000000000)
     woo = getattr(pm, 'size.hr')
예제 #13
0
 def test_update(self):
     old = PathMeta(id='0', size=10, file_id=1)
     new = PathMeta(id='0', size=10, checksum='asdf')
     merged = PrimaryCache._update_meta(old, new)
     assert merged == PathMeta(id='0', size=10, file_id=1, checksum='asdf')
예제 #14
0
 def test(self):
     zt = TestLocalPath(test_path) / 'zero-test'
     cache = TestCachePath(zt, meta=PathMeta(id='0'))
     assert cache.meta