Exemplo n.º 1
0
class TestDirectoryTree(unittest.TestCase):

    def setUp(self):
        self.testfilepath = tarman.tests.test_containers.__file__
        self.testdirectory = os.path.dirname(self.testfilepath)
        self.testdatapath = os.path.join(
            self.testdirectory, 'testdata', 'testdata'
        )
        self.fs = FileSystem()

    def test_init(self):
        self.assertIsNotNone(
            DirectoryTree(self.testdatapath, self.fs)
        )

    def test_add_file(self):
        tree = DirectoryTree(self.testdatapath, self.fs)
        path1 = self.fs.join(self.testdatapath, 'a', 'aa', 'aaa')
        path2 = self.fs.join(self.testdatapath, 'a', 'aa')
        tree.add(path1)
        self.assertIn(path1, tree)
        self.assertIn(path2, tree)  # not-added one-level-up directory

    def test_add_dir(self):
        tree = DirectoryTree(self.testdatapath, self.fs)
        dir1 = self.fs.join(self.testdatapath, 'a', 'ab')
        tree.add(dir1)
        self.assertIn(dir1, tree)

    def test_out_of_range(self):
        tree = DirectoryTree(self.testdatapath, self.fs)

        # one level up directory
        dir1 = self.fs.abspath(self.fs.join(self.testdatapath, '..'))
        with self.assertRaises(OutOfRange):
            tree.add(dir1)

        # completely different directory
        with tempfile.NamedTemporaryFile() as f:
            with self.assertRaises(OutOfRange):
                tree.add(f.name)
Exemplo n.º 2
0
class TestFileSystem(unittest.TestCase):
    def setUp(self):
        self.fs = FileSystem()
        self.testcwd = os.getcwd()
        self.testfilepath = tarman.tests.test_containers.__file__
        self.testdirectory = os.path.dirname(self.testfilepath)
        self.testdatadir = os.path.join(self.testdirectory, 'testdata')

    def test_container(self):
        self.assertTrue(isinstance(self.fs, Container))

    def test_listdir(self):
        self.assertEqual(self.fs.listdir(self.testdirectory),
                         os.listdir(self.testdirectory))

    def test_isenterable(self):
        self.assertTrue(self.fs.isenterable(self.testdirectory))

    def test_abspath(self):
        self.assertEqual(self.fs.abspath('.'), self.testcwd)

    def test_dirname(self):
        self.assertEqual(self.fs.dirname(self.testfilepath),
                         self.testdirectory)

    def test_basename(self):
        self.assertEqual(self.fs.basename(self.testfilepath),
                         os.path.basename(self.testfilepath))

    def test_join(self):
        self.assertEqual(self.fs.join('/home', 'someone', 'bin', 'python'),
                         '/home/someone/bin/python')

    def test_split(self):
        self.assertEqual(self.fs.split('/home/someone/bin/python'),
                         ('/home/someone/bin', 'python'))

    def test_samefile(self):
        self.assertTrue(self.fs.samefile(self.testfilepath, self.testfilepath))
        self.assertFalse(
            self.fs.samefile(self.testfilepath,
                             tarman.tests.test_tree.__file__))

    def test_count_items(self):
        self.assertEqual(self.fs.count_items(self.testdatadir), 17)
        self.assertEqual(self.fs.count_items(self.testdatadir, stop_at=9), 9)
Exemplo n.º 3
0
class TestFileSystem(unittest.TestCase):

    def setUp(self):
        self.fs = FileSystem()
        self.testcwd = os.getcwd()
        self.testfilepath = tarman.tests.test_containers.__file__
        self.testdirectory = os.path.dirname(self.testfilepath)
        self.testdatadir = os.path.join(self.testdirectory, 'testdata')

    def test_container(self):
        self.assertTrue(isinstance(self.fs, Container))

    def test_listdir(self):
        self.assertEqual(
            self.fs.listdir(self.testdirectory),
            os.listdir(self.testdirectory)
        )

    def test_isenterable(self):
        self.assertTrue(self.fs.isenterable(self.testdirectory))

    def test_abspath(self):
        self.assertEqual(self.fs.abspath('.'), self.testcwd)

    def test_dirname(self):
        self.assertEqual(
            self.fs.dirname(self.testfilepath), self.testdirectory
        )

    def test_basename(self):
        self.assertEqual(
            self.fs.basename(self.testfilepath),
            os.path.basename(self.testfilepath)
        )

    def test_join(self):
        self.assertEqual(
            self.fs.join('/home', 'someone', 'bin', 'python'),
            '/home/someone/bin/python'
        )

    def test_split(self):
        self.assertEqual(
            self.fs.split('/home/someone/bin/python'),
            ('/home/someone/bin', 'python')
        )

    def test_samefile(self):
        self.assertTrue(
            self.fs.samefile(self.testfilepath, self.testfilepath)
        )
        self.assertFalse(
            self.fs.samefile(
                self.testfilepath,
                tarman.tests.test_tree.__file__
            )
        )

    def test_count_items(self):
        self.assertEqual(
            self.fs.count_items(self.testdatadir),
            17
        )
        self.assertEqual(
            self.fs.count_items(self.testdatadir, stop_at=9),
            9
        )