def test_get_attrs(self): model = fsnav.FSModel(self.tmpdir) self.assertEqual( _dict_clone_filtered(model.get_attrs(self.test_file)), { '@type': 'CreativeWork', 'alternativeType': 'file', 'size': 22, '@id': 'test_file.txt', 'name': 'test_file.txt', 'path': '/test_file.txt' }) self.assertEqual( _dict_clone_filtered(model.get_attrs(self.dummydir1), [ 'created', 'size', ]), { '@type': 'ItemList', 'alternativeType': 'folder', '@id': 'dummydir1', 'name': 'dummydir1', 'path': '/dummydir1/' }) self.assertEqual( _dict_clone_filtered(model.get_attrs(self.dummydirfile1)), { '@type': 'CreativeWork', 'alternativeType': 'file', 'size': 13, '@id': 'file1', 'name': 'file1', 'path': '/dummydir2/file1' })
def test_get_struct_error(self): model = fsnav.FSModel(self.tmpdir) with self.assertRaises(OSError): # FileNotFoundError model.get_struct('/no_such_dir') with self.assertRaises(OSError): # FileNotFoundError model.get_struct('/no_such_dir')
def test_path_to_fs_path(self): model = fsnav.FSModel(self.tmpdir) with self.assertRaises(ValueError): model.path_to_fs_path('welp') result = model.path_to_fs_path('/readme.txt') self.assertTrue(result.startswith(self.tmpdir)) self.assertTrue(result.endswith('readme.txt'))
def test_listdir(self): model = fsnav.FSModel(self.tmpdir) self.assertEqual(sorted(model._listdir(sep)), []) # No issue between this or the one with a separtor self.assertEqual(sorted(model._listdir(self.tmpdir)), ['dummydir1', 'dummydir2', 'test_file.txt']) self.assertEqual(sorted(model._listdir(self.tmpdir + sep)), ['dummydir1', 'dummydir2', 'test_file.txt']) self.assertEqual(sorted(model._listdir(self.dummydir1)), ['..'])
def test_get_attrs_data_pardir(self): # for the case where legitimate parent dir entry is required model = fsnav.FSModel(self.tmpdir) self.assertEqual( _dict_clone_filtered(model.get_attrs(join(self.dummydir2, pardir))), { 'alternativeType': 'folder', '@type': 'ItemList', 'size': 0, '@id': '..', 'name': '..', 'path': '/', })
def test_get_struct_dir_contents(self): model = fsnav.FSModel(self.tmpdir) result = model.get_struct(self.dummydir2) self.assertEqual( _dict_clone_filtered(result['mainEntity'], [ 'created', 'size', 'itemListElement', ]), { 'alternativeType': 'folder', '@type': 'ItemList', '@id': 'dummydir2', 'name': 'dummydir2', 'path': '/dummydir2/', }) self.assertEqual(len(result['mainEntity']['itemListElement']), 4)
def test_get_struct_file(self): model = fsnav.FSModel(self.tmpdir) self.assertEqual( _dict_clone_filtered( model.get_struct(self.test_file)['mainEntity']), { 'alternativeType': 'file', '@type': 'CreativeWork', 'size': 22, '@id': 'test_file.txt', 'name': 'test_file.txt', 'path': '/test_file.txt', }) self.assertEqual( _dict_clone_filtered( model.get_struct(self.dummydirfile1)['mainEntity']), { 'alternativeType': 'file', '@type': 'CreativeWork', 'size': 13, '@id': 'file1', 'name': 'file1', 'path': '/dummydir2/file1', })