def test_countfiles_all_nt(self):
        """Testing def main_flow.

        Recursive/non recursive counting.
        Testing for hidden files is not carried out here.
        Equivalent to "python __main__.py ~/.../tests/data_for_tests -a -nt"
        :return:
        """
        self.assertEqual(
            main_flow([self.get_locations('data_for_tests'), '-nt']), 14)
        self.assertEqual(
            main_flow([self.get_locations('data_for_tests'), '-nt', '-nr']), 4)
    def test_for_hidden_win(self):
        """Testing def main_flow.

        Equivalent to
        "python __main__.py ~/.../tests/data_for_tests -nr"
        and "python __main__.py ~/.../tests/data_for_tests -nr -a"
        :return:
        """
        self.assertEqual(
            main_flow(
                [self.get_locations('test_hidden_windows'), '-nr', '-nt']), 1)
        self.assertEqual(
            main_flow([
                self.get_locations('test_hidden_windows'), '-nr', '-nt', '-a'
            ]), 2)
    def test_countfiles_fe(self):
        """Testing def main_flow.

        Recursive default counting.
        Equivalent to
        "python __main__.py ~/.../tests/data_for_tests/django_staticfiles_for_test -fe {extension}"
        Non recursive counting.
        Equivalent to
        "python __main__.py ~/.../tests/data_for_tests/django_staticfiles_for_test -nr -fe {extension}"
        :return:
        """
        location = self.get_locations('data_for_tests',
                                      'django_staticfiles_for_test')
        extensions = {'py': 1, 'json': 1, 'woff': 1, '.': 1}
        nr_extensions = {'css': 0, '.': 1, 'woff': 0}
        for k, v in extensions.items():
            with self.subTest(k=k, v=v):
                self.assertEqual(main_flow([location, '-fe', f'{k}']), v)
        for k, v in nr_extensions.items():
            with self.subTest(k=k, v=v):
                self.assertEqual(main_flow([location, '-nr', '-fe', f'{k}']),
                                 v)
Пример #4
0
Timer(stmt='pass', setup='pass', timer=<timer function>, globals=None)
Timer.repeat(repeat=3, number=1000000)
"""
import timeit
import sys
import os
from countfiles.utils.file_handlers import search_files, count_file_extensions1, count_files_by_extension
from countfiles.__main__ import main_flow


def get_locations(*args):
    return os.path.normpath(os.path.join(os.path.expanduser('~/'), *args))


main_no_feedback_no_table = """
main_flow([location, '-a', '-nf', '-nt'])
"""

main_feedback_table = """
main_flow([location, '-a'])
"""

search_files_feedback = """
data = search_files(dirpath=location, extension='', recursive=True, include_hidden=True)
counter = count_file_extensions1(file_paths=data, no_feedback=False)
"""

count_files_feedback = """
data = count_files_by_extension(dirpath=location, no_feedback=False, recursive=True, include_hidden=True)
"""