6.23.3.4. Test routine 1
First, create some files to compare!
Start data section to interscript/tests/diff1.dat[1
/1
]
1: A file with several lines of text.
2: A line to be deleted.
3: To be used by the diff module test.
4: This line will be changed.
5: The diff module is used to compare and patch test files.
6:
Start data section to interscript/tests/diff2.dat[1
/1
]
1: A file with several lines of text.
2: To be used by the diff module test.
3: This line is changed.
4: A NEW LINE INSERTED.
5: The diff module is used to compare and patch test files.
6:
Start python section to interscript/tests/test_diff.py[1
/1
]
1: #line 192 "diff.ipk"
2: import sys
3: import string
4: sys.path = [''] + sys.path
5: import interscript.utilities.diff
6: diff = interscript.utilities.diff
7: cmp = diff.compare_files('diff1.dat', 'diff1.dat')
8: assert cmp
9: cmp = diff.compare_files('diff1.dat', 'diff2.dat')
10: assert not cmp
11: patch = diff.diff_files('diff1.dat','diff2.dat')
12: print 'patch below'
13: print patch
14: print
15: diff.patch_file('diff1.dat',patch,'diff3.dat')
16: cmp = diff.compare_files('diff2.dat','diff3.dat')
17: assert cmp
18: f = open('diff1.dat')
19: d1 = f.readlines()
20: f.close()
21: for i in range(len(d1)): d1[i] = string.rstrip(d1[i])
22: f = open('diff2.dat')
23: d2 = f.readlines()
24: for i in range(len(d2)): d2[i] = string.rstrip(d2[i])
25: f.close()
26:
27: d = diff.diff_lines(d1,d2)
28: for section in d:
29: print '*****'
30: for part in section:
31: print part
32:
Now run it.
Start output section of "/usr/local/bin/python" interscript/tests/test_diff.py
Command returned 256
1: diff: diff1.dat: No such file or directory
2: diff: diff1.dat: No such file or directory
3: diff: diff2.dat: No such file or directory
4: Traceback (most recent call last):
5: File "interscript/tests/test_diff.py", line 10, in ?
6: assert not cmp
7: AssertionError