]> git.phdru.name Git - ppu.git/blob - tests/test_rm.py
Feat(rm): Add option -f
[ppu.git] / tests / test_rm.py
1 #! /usr/bin/env python
2
3 import subprocess
4 import sys
5 from ppu_tu import setup, teardown, find_in_path  # noqa
6 from ppu_tu import create_files, assert_files_exist, assert_files_not_exist
7
8
9 test_prog_path = find_in_path('rm.py')
10
11
12 def test_rm():
13     create_files(['test1', 'test2'])
14     assert_files_exist(['test1', 'test2'])
15     assert subprocess.call(
16         [sys.executable, test_prog_path, "test2"]) == 0
17     assert_files_exist('test1')
18     assert_files_not_exist('test2')
19
20     create_files(['test1', 'test2'])
21     assert_files_exist(['test1', 'test2'])
22     assert subprocess.call(
23         [sys.executable, test_prog_path, "-r", "test2"]) == 0
24     assert_files_exist('test1')
25     assert_files_not_exist('test2')
26
27     assert subprocess.call(
28         [sys.executable, test_prog_path, "test3"]) == 1  # not exists
29     assert subprocess.call(
30         [sys.executable, test_prog_path, "-f", "test3"]) == 0
31
32
33 def test_rm_recursive():
34     create_files(['test'])
35     create_files(['test'], 'subdir/subd2')
36     assert_files_exist(['test', 'subdir/subd2/test'])
37     assert subprocess.call(
38         [sys.executable, test_prog_path, "subdir"]) == 1
39     assert subprocess.call(
40         [sys.executable, test_prog_path, "-r", "subdir"]) == 0
41     assert_files_exist('test')
42     assert_files_not_exist(['subdir/subd2/test'])
43
44     assert subprocess.call(
45         [sys.executable, test_prog_path, "-r", "test3"]) == 1  # not exists
46     assert subprocess.call(
47         [sys.executable, test_prog_path, "-rf", "test3"]) == 0