Ejemplo n.º 1
0
    def test__list_files__non_existing_directory__return_empty_list(self):
        # Act
        dw = DirWalker()
        result = dw.list_files(os.path.join(self.root_path, 'failure'))

        # Assert
        self.assertListEqual([], sorted(result))
Ejemplo n.º 2
0
    def test__set_extension_filter__value_none__filter_none(self):
        # Arrange
        dw = DirWalker()

        # Act
        dw.set_allowed_extensions(None)

        # Assert
        self.assertIsNone(dw._allowed_extensions)
Ejemplo n.º 3
0
    def test__set_search_recursive__boolean_value__set_value(self):
        # Arrange
        dw = DirWalker()

        # Act
        dw.set_search_recursive(False)

        # Assert
        self.assertFalse(dw._search_recursive)
Ejemplo n.º 4
0
    def test__has_allowed_extension__right_extension__include_file(self):
        # Arrange
        dw = DirWalker(allowed_extensions=['txt'])
        file = "MyFile.txt"

        # Act
        result = dw.has_allowed_extension(file)

        # Assert
        self.assertTrue(result)
Ejemplo n.º 5
0
    def test__has_allowed_extension__filter_is_none__no_filtering(self):
        # Arrange
        dw = DirWalker(allowed_extensions=None)
        file = "MyFile.txt"

        # Act
        result = dw.has_allowed_extension(file)

        # Assert
        self.assertTrue(result)
Ejemplo n.º 6
0
    def test__set_search_recursive__none_boolean_value__set_true(self):
        # Arrange
        dw = DirWalker()
        val = 'wrong type'

        # Act
        dw.set_search_recursive(val)

        # Assert
        self.assertTrue(dw._search_recursive)
Ejemplo n.º 7
0
    def test__set_allowed_extensions__empty_list__set_none(self):
        # Arrange
        dw = DirWalker()
        val = []

        # Act
        dw.set_allowed_extensions(val)

        # Assert
        self.assertIsNone(dw._allowed_extensions)
Ejemplo n.º 8
0
    def test__set_allowed_extensions__multiple_words__is_list(self):
        # Arrange
        dw = DirWalker()
        val = ['txt', 'py']

        # Act
        dw.set_allowed_extensions(val)

        # Assert
        self.assertEqual(val, dw._allowed_extensions)
Ejemplo n.º 9
0
    def test__set_allowed_extensions__single_word__is_list(self):
        # Arrange
        dw = DirWalker()
        val = 'txt'

        # Act
        dw.set_allowed_extensions(val)

        # Assert
        self.assertEqual([val], dw._allowed_extensions)
Ejemplo n.º 10
0
    def test__has_allowed_extension__wrong_extension__exclude_file(self):
        # Arrange
        dw = DirWalker(allowed_extensions=['py'])
        file = "MyFile.txt"

        # Act
        result = dw.has_allowed_extension(file)

        # Assert
        self.assertFalse(result)
Ejemplo n.º 11
0
    def test__list_files_search__non_recursive__no_files_subdirectory(self):
        # Arrange
        dw = DirWalker(recursive=False)
        file_txt = File(self.txt_path)
        no_recursive_list = [file_txt, ]

        # Act
        result = dw.list_files(self.root_path)

        # Assert
        self.assertListEqual(sorted(no_recursive_list), sorted(result))
Ejemplo n.º 12
0
    def test__list_files__search_filter_extensions__include_files(self):
        # Arrange
        dw = DirWalker(allowed_extensions=['txt', '.log'])
        file_txt = File(self.txt_path)
        file_log = File(self.log_path)
        recursive_list = [file_txt, file_log]

        # Act
        result = dw.list_files(self.root_path)

        # Assert
        self.assertListEqual(sorted(recursive_list), sorted(result))
Ejemplo n.º 13
0
    def test__list_files__search_recursive__all_included(self):
        # Arrange
        dw = DirWalker()
        file_txt = File(self.txt_path)
        file_py = File(self.py_path)
        file_log = File(self.log_path)
        recursive_list = [file_txt, file_py, file_log]

        # Act
        result = dw.list_files(self.root_path)

        # Assert
        self.assertListEqual(sorted(recursive_list), sorted(result))
Ejemplo n.º 14
0
    def test__constructor__default(self):
        # Act
        dw = DirWalker()

        # Assert
        self.assertIsNone(dw._allowed_extensions)
        self.assertTrue(dw._search_recursive)
Ejemplo n.º 15
0
    def test__constructor__presets(self):
        # Arrange
        ext = ['txt', 'py']

        # Act
        dw = DirWalker(ext, False)

        # Assert
        self.assertEqual(ext, dw._allowed_extensions)
        self.assertFalse(dw._search_recursive)
Ejemplo n.º 16
0
    def test__is_directory__invalid_path__return_false(self):
        # Act
        result = DirWalker.is_directory(self.log_path)

        # Assert
        self.assertFalse(result)
Ejemplo n.º 17
0
    def test__is_directory__non_existing_directory__return_false(self):
        # Act
        result = DirWalker.is_directory(os.path.join(self.root_path, 'failure'))

        # Assert
        self.assertFalse(result)
Ejemplo n.º 18
0
    def test__is_directory__valid_path__return_true(self):
        # Act
        result = DirWalker.is_directory(self.root_path)

        # Assert
        self.assertTrue(result)