def test_output(): with tempfile.TemporaryDirectory(suffix='-tree') as tmpdirname: num_files = random.randint(2, 8) file_numbers = random.sample(range(1, 9), num_files) file_numbers.sort() for file_num in file_numbers: path = os.path.join(tmpdirname, 'file{}.txt'.format(file_num)) Path(path).touch() expected = helpers.run_and_capture(['tree', tmpdirname]) actual = helpers.run_and_capture(['./pytree.py', tmpdirname]) assert expected == actual
def test_file_dir_names(): path = 'examples/simple' output = helpers.run_and_capture(['./pytree.py', path]) names = re.findall('[a-z]+(?:\.[a-z]+)?', output) names.sort() assert names == [ 'another', 'bites', 'directories', 'dot.jpg', 'dust', 'examples', 'files', 'one.txt', 'simple', 'the' ]
def test_file_dir_names(): path = 'examples/flat' output = helpers.run_and_capture(['./pytree.py', path]) names = re.findall('[a-z]+\d?(?:\.[a-z]+)?', output) names.sort() assert names == [ 'directories', 'examples', 'file1.txt', 'file2.txt', 'file3.txt', 'files', 'flat' ]
def test_full_output(emptydir): expected = helpers.run_and_capture(['tree', emptydir]) actual = helpers.run_and_capture(['./pytree.py', emptydir]) assert expected == actual
def test_num_files(emptydir): output = helpers.run_and_capture(['./pytree.py', emptydir]) assert "0 files" in output
def test_without_path(monkeypatch): monkeypatch.chdir('examples') expected = helpers.run_and_capture(['tree']) actual = helpers.run_and_capture(['../pytree.py']) assert expected == actual
def test_num_directories(): path = 'examples/flat' output = helpers.run_and_capture(['./pytree.py', path]) assert "0 directories" in output
def test_full_output(): path = 'examples/flat' expected = helpers.run_and_capture(['tree', path]) actual = helpers.run_and_capture(['./pytree.py', path]) assert expected == actual
def test_num_files(): path = 'examples/simple' output = helpers.run_and_capture(['./pytree.py', path]) assert "4 files" in output