diff options
author | William Deegan <bill@baddogconsulting.com> | 2017-03-24 21:55:07 (GMT) |
---|---|---|
committer | William Deegan <bill@baddogconsulting.com> | 2017-03-24 21:55:07 (GMT) |
commit | 94424fe97f8a846a6ec1a97f4c363ac0737719b6 (patch) | |
tree | ad47b56bdf48d6e19f3c7d5edb274fc92c40fb49 /test/textfile.py | |
parent | 871e8747323c362ddbe01dc03323f775430c944a (diff) | |
download | SCons-94424fe97f8a846a6ec1a97f4c363ac0737719b6.zip SCons-94424fe97f8a846a6ec1a97f4c363ac0737719b6.tar.gz SCons-94424fe97f8a846a6ec1a97f4c363ac0737719b6.tar.bz2 |
fix py2/3. Also fix py2 win32 broken tests
Diffstat (limited to 'test/textfile.py')
-rw-r--r-- | test/textfile.py | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/test/textfile.py b/test/textfile.py index f82f50a..91e95e9 100644 --- a/test/textfile.py +++ b/test/textfile.py @@ -30,11 +30,13 @@ import os test = TestSCons.TestSCons() -foo1 = test.workpath('foo1.txt') +foo1 = test.workpath('foo1.txt') #foo2 = test.workpath('foo2.txt') #foo1a = test.workpath('foo1a.txt') #foo2a = test.workpath('foo2a.txt') +match_mode = 'rb' + test.write('SConstruct', """ env = Environment(tools=['textfile']) data0 = ['Goethe', 'Schiller'] @@ -55,43 +57,48 @@ env.Substfile('bar2', data, LINESEPARATOR='|*') data.append(Value('')) env.Substfile('bar1a.txt', data) env.Substfile('bar2a.txt', data, LINESEPARATOR='|*') -""") +""", mode='w') -test.run(arguments = '.') +test.run(arguments='.') textparts = ['lalala', '42', 'Goethe', 'Schiller', 'tanteratei'] -foo1Text = os.linesep.join(textparts) -foo2Text = '|*'.join(textparts) +foo1Text = os.linesep.join(textparts) +foo2Text = '|*'.join(textparts) foo1aText = foo1Text + os.linesep foo2aText = foo2Text + '|*' -test.up_to_date(arguments = '.') +test.up_to_date(arguments='.') files = list(map(test.workpath, ( - 'foo1.txt', 'foo2.txt', 'foo1a.txt', 'foo2a.txt', - 'bar1', 'bar2', 'bar1a.txt', 'bar2a.txt', - ))) + 'foo1.txt', 'foo2.txt', 'foo1a.txt', 'foo2a.txt', + 'bar1', 'bar2', 'bar1a.txt', 'bar2a.txt', +))) + + def check_times(): - # make sure the files didn't get rewritten, because nothing changed: + """ + make sure the files didn't get rewritten, because nothing changed: + """ before = list(map(os.path.getmtime, files)) # introduce a small delay, to make the test valid test.sleep() # should still be up-to-date - test.up_to_date(arguments = '.') + test.up_to_date(arguments='.') after = list(map(os.path.getmtime, files)) test.fail_test(before != after) + # make sure that the file content is as expected -test.must_match('foo1.txt', foo1Text) -test.must_match('bar1', foo1Text) -test.must_match('foo2.txt', foo2Text) -test.must_match('bar2', foo2Text) -test.must_match('foo1a.txt', foo1aText) -test.must_match('bar1a.txt', foo1aText) -test.must_match('foo2a.txt', foo2aText) -test.must_match('bar2a.txt', foo2aText) +test.must_match('foo1.txt', foo1Text, mode=match_mode) +test.must_match('bar1', foo1Text, mode=match_mode) +test.must_match('foo2.txt', foo2Text, mode=match_mode) +test.must_match('bar2', foo2Text, mode=match_mode) +test.must_match('foo1a.txt', foo1aText, mode=match_mode) +test.must_match('bar1a.txt', foo1aText, mode=match_mode) +test.must_match('foo2a.txt', foo2aText, mode=match_mode) +test.must_match('bar2a.txt', foo2aText, mode=match_mode) check_times() # write the contents and make sure the files @@ -132,17 +139,23 @@ s = env.Substfile('sub5', s, SUBST_DICT = sub1) s = env.Substfile('sub6', t, SUBST_DICT = sub3) """, mode='w') -test.run(arguments = '.') +test.run(arguments='.') -line1 = 'This line has no substitutions' +line1 = 'This line has no substitutions' line2a = 'This line has @subst@ substitutions' line2b = 'This line has most substitutions' line3a = 'This line has %subst% substitutions' line3b = 'This line has many substitutions' -def matchem(file, lines): + +def matchem(match_file, lines): + """ + Join all the lines with correct line separator, + then compare + """ lines = os.linesep.join(lines) - test.must_match(file, lines, mode='r') + test.must_match(match_file, lines, mode=match_mode) + matchem('text.txt', [line1, line2a, line3a]) matchem('sub1', [line1, line2a, line3a]) @@ -152,6 +165,6 @@ matchem('sub4', [line1, line2a, line3b]) matchem('sub5', [line1, line2b, line3b]) matchem('sub6', [line1, line2b, line3b]) -test.up_to_date(arguments = '.') +test.up_to_date(arguments='.') test.pass_test() |