]> git.phdru.name Git - ppu.git/blob - tests/test_cmp.py
Add cmp.py
[ppu.git] / tests / test_cmp.py
1 #! /usr/bin/env python
2
3 import os
4 import shutil
5 import subprocess
6 import sys
7 from tempfile import mkdtemp
8 from find_in_path import find_in_path
9
10
11 tmp_dir = None
12
13 test_prog_path = find_in_path('cmp.py')
14 if not test_prog_path:
15     sys.exit("Cannot find cmp.py in %s" % os.environ["PATH"])
16
17
18 def setup():
19     global tmp_dir
20     tmp_dir = mkdtemp()
21     os.chdir(tmp_dir)
22
23
24 def teardown():
25     os.chdir(os.sep)  # To the root of the FS
26     shutil.rmtree(tmp_dir)
27
28
29 def create_file(name, content):
30     with open(name, 'w') as fp:
31         fp.write(content)
32
33
34 def test_cmp_equal():
35     create_file('test1', 'test')
36     create_file('test2', 'test')
37     assert subprocess.call(
38         [sys.executable, test_prog_path, "-i", "test1", "test2"]) == 0
39
40     create_file('test3', 'test3')
41     create_file('test4', 'test4')
42     assert subprocess.call(
43         [sys.executable, test_prog_path, "-i", "test3", "test4"]) == 1