6.13.2.4. Test routine 1

6.13.2.4. Test routine 1

First, create some files to compare!
Start data section to interscript/tests/diff1.dat[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: 
End data section to interscript/tests/diff1.dat[1]
Start data section to interscript/tests/diff2.dat[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: 
End data section to interscript/tests/diff2.dat[1]
Start python section to interscript/tests/test_diff.py[1]
     1: #line 191 "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: 
End python section to interscript/tests/test_diff.py[1]
Now run it.
Start output section of /usr/local/bin/python interscript/tests/test_diff.py
     1: Interscript Package: version 1.0a7 build 1302
     2: thread available
     3: Interscript version 1.0a7 build 1302
     4: Built by root on ruby at Thu Nov 12, 1998 at 12:57 PM (UTC)
     5: Generated by 1.0a7 buildno 1300 host ruby
     6: at Thu Nov 12, 1998 at 12:57 PM (UTC)
     7: patch below
     8: *** diff1.dat	Tue Aug 11 04:10:58 1998
     9: --- diff2.dat	Tue Aug 11 04:10:58 1998
    10: ***************
    11: *** 1,6 ****
    12:   A file with several lines of text.
    13: - A line to be deleted.
    14:   To be used by the diff module test.
    15: ! This line will be changed.
    16:   The diff module is used to compare and patch test files.
    17: 
    18: --- 1,6 ----
    19:   A file with several lines of text.
    20:   To be used by the diff module test.
    21: ! This line is changed.
    22: ! A NEW LINE INSERTED.
    23:   The diff module is used to compare and patch test files.
    24: 
    25: 
    26: 
    27: patch -s -c -o diff3.dat diff1.dat -
    28: *****
    29: [[1, 1], '  2:- A line to be deleted.']
    30: [[0, 0]]
    31: *****
    32: [[3, 1], '  4:! This line will be changed.']
    33: [[2, 2], '  3:! This line is changed.', '  4:! A NEW LINE INSERTED.']
End output section to /usr/local/bin/python interscript/tests/test_diff.py