def test_cd_root(self): dir_ = F('/tmp/wtfile') self.assertEqual(dir_.cd('...'), '/') self.assertEqual(dir_.cd('...').cd('...'), '/') dir_ = F('tmp/wtfile') self.assertEqual(dir_.cd('...'), '') self.assertEqual(dir_.cd('...').cd('...'), '')
def test_f_basic_io(self): tmp = F('/tmp') tmp = tmp.clear('wtfile') self.assertEqual(tmp, '/tmp/wtfile') self.assertEqual(tmp.isdir(), True) # try again to make sure it's able to remove and recreate tmp = F('/tmp', 'wtfile').clear() self.assertEqual(tmp, '/tmp/wtfile') self.assertEqual(tmp.isdir(), True)
def test_cd(self): dir_ = F('/tmp/wtfile/folder') self.assertEqual(dir_.cd('..'), '/tmp/wtfile') self.assertEqual(dir_.cd('...'), '/tmp') self.assertEqual(dir_.cd('subfolder'), '/tmp/wtfile/folder/subfolder') self.assertEqual(dir_.cd('./subfolder'), '/tmp/wtfile/folder/subfolder') self.assertEqual(dir_.cd('../folder2'), '/tmp/wtfile/folder2')
def test_radd(self, file): self.assertEqual('x' + file.ext, '.xfile') self.assertEqual('x' + F('file').ext, '.x') self.assertEqual('x' + file.stem, 'xtmp') self.assertEqual('x' + file.name, 'xtmp.file') self.assertEqual(type('x' + file.ext), FExt) self.assertEqual(type('x' + file.stem), FStem) self.assertEqual(type('x' + file.name), FName)
def decorated(self, *args, **kwargs): tmp = F('/tmp/wtfile') if clear: tmp.clear() f = tmp('tmp.file').touch() def _cleanup(): if cleanup: tmp.clear() else: f.rm() try: fn(self, f, *args, **kwargs) except Exception as e: _cleanup() raise e else: _cleanup()
def test_expanduser(self): user = os.getenv('USER') self.assertEqual(F('~/tmp').expanduser(), f'/home/{user}/tmp') self.assertEqual(F('/~/tmp').expanduser(), f'/~/tmp')
def test_set_DIR(self): F().DIR = '/tmp'
def test_root(self): self.assertEqual(F('/tmp/wtfile').root, '/') self.assertEqual(F('~/tmp/wtfile').root, '~') self.assertEqual(F('./tmp/wtfile').root, '.') self.assertEqual(F('tmp').root, 'tmp') self.assertEqual(F('tmp/wtfile').root, 'tmp')
def test_call(self): dir_ = F('/tmp/wtfile') self.assertEqual( dir_('folder')('tmp.file'), '/tmp/wtfile/folder/tmp.file') self.assertEqual(dir_('folder', 'tmp.file'), '/tmp/wtfile/folder/tmp.file')
def test_ismount(self, file): self.assertEqual(file.ismount(), False) self.assertEqual(F('/').ismount(), True)
def setUp(self): self.dir = F('/tmp').clear('wtfile')
def test_to_str(self): f = F('/tmp/wtfile') self.assertEqual(f.to_str(), '/tmp/wtfile') self.assertEqual(type(f.to_str()), str)
def test_div(self): self.assertEqual('/tmp' / F('wtfile') / 'tmp.file', '/tmp/wtfile/tmp.file') self.assertEqual(type('/tmp' / F('wtfile') / 'tmp.file'), F)
def test_radd(self): self.assertEqual('x' + F(''), 'x') self.assertEqual('/tmp' + F('/wtfile'), '/tmp/wtfile') self.assertEqual(type('/tmp' + F('/wtfile')), F)
def test_add(self): self.assertEqual(F('') + 'x', 'x') self.assertEqual(F('/tmp') + '/wtfile', '/tmp/wtfile') self.assertEqual(type(F('/tmp') + '/wtfile'), F)
def test_expandvars(self): user = os.getenv('USER') self.assertEqual(F('$USER/tmp').expandvars(), f'{user}/tmp') self.assertEqual(F('/$USER/tmp').expandvars(), f'/{user}/tmp')
def test_expand(self): user = os.getenv('USER') self.assertEqual( F('~/tmp/$USER/x').expand(), f'/home/{user}/tmp/{user}/x')
def test_f_init(self): try: F('/tmp', 'wtfile') except Exception: self.assertEqual(0, 1)
def test_isabs(self): self.assertEqual(F('/tmp/wtfile').isabs(), True) self.assertEqual(F('tmp/wtfile').isabs(), False)
def test_norm(self): f = F('/tmp/./wtfile') self.assertEqual(f.norm(), '/tmp/wtfile') self.assertEqual(f.normal(), '/tmp/wtfile')
def test_matchcase(self): f = F('/tmp/wtfile/stem.eXt') self.assertEqual(f.matchcase('*.eXt'), True) self.assertEqual(f.matchcase('*.ext'), False) self.assertEqual(f.matchcase('*.xt'), False) self.assertEqual(F('x.ext').match('*.eXt'), False)
def test_init_empty(self): self.assertEqual(F(), '')