diff options
Diffstat (limited to 'src/engine/SCons/ActionTests.py')
-rw-r--r-- | src/engine/SCons/ActionTests.py | 280 |
1 files changed, 186 insertions, 94 deletions
diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index 616c949..ed2412b 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2001 - 2016 The SCons Foundation +# Copyright (c) 2001 - 2017 The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -21,7 +21,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/ActionTests.py rel_2.5.1:3735:9dc6cee5c168 2016/11/03 14:02:02 bdbaddog" +__revision__ = "src/engine/SCons/ActionTests.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog" # Define a null function and a null class for use as builder actions. # Where these are defined in the file seems to affect their byte-code @@ -61,7 +61,7 @@ test = TestCmd.TestCmd(workdir = '') test.write('act.py', """\ import os, string, sys f = open(sys.argv[1], 'w') -f.write("act.py: '" + string.join(sys.argv[2:], "' '") + "'\\n") +f.write("act.py: '" + "' '".join(sys.argv[2:]) + "'\\n") try: if sys.argv[3]: f.write("act.py: '" + os.environ[sys.argv[3]] + "'\\n") @@ -231,7 +231,7 @@ def test_positional_args(pos_callback, cmd, **kw): """ act = SCons.Action.Action(cmd, **kw) pos_callback(act) - assert act.varlist is (), act.varlist + assert act.varlist == (), act.varlist if not isinstance(act, SCons.Action._ActionAction): # only valid cmdstrfunc is None @@ -265,7 +265,7 @@ def test_positional_args(pos_callback, cmd, **kw): """Test handling of bad cmdstrfunc arguments """ try: a = SCons.Action.Action(cmd, [], **kw) - except SCons.Errors.UserError, e: + except SCons.Errors.UserError as e: s = str(e) m = 'Invalid command display variable' assert s.find(m) != -1, 'Unexpected string: %s' % s @@ -316,7 +316,7 @@ class ActionTestCase(unittest.TestCase): """ a1 = SCons.Action.Action(["x", "y", "z", [ "a", "b", "c"]]) assert isinstance(a1, SCons.Action.ListAction), a1 - assert a1.varlist is (), a1.varlist + assert a1.varlist == (), a1.varlist assert isinstance(a1.list[0], SCons.Action.CommandAction), a1.list[0] assert a1.list[0].cmd_list == "x", a1.list[0].cmd_list assert isinstance(a1.list[1], SCons.Action.CommandAction), a1.list[1] @@ -328,7 +328,7 @@ class ActionTestCase(unittest.TestCase): a2 = SCons.Action.Action("x\ny\nz") assert isinstance(a2, SCons.Action.ListAction), a2 - assert a2.varlist is (), a2.varlist + assert a2.varlist == (), a2.varlist assert isinstance(a2.list[0], SCons.Action.CommandAction), a2.list[0] assert a2.list[0].cmd_list == "x", a2.list[0].cmd_list assert isinstance(a2.list[1], SCons.Action.CommandAction), a2.list[1] @@ -341,7 +341,7 @@ class ActionTestCase(unittest.TestCase): a3 = SCons.Action.Action(["x", foo, "z"]) assert isinstance(a3, SCons.Action.ListAction), a3 - assert a3.varlist is (), a3.varlist + assert a3.varlist == (), a3.varlist assert isinstance(a3.list[0], SCons.Action.CommandAction), a3.list[0] assert a3.list[0].cmd_list == "x", a3.list[0].cmd_list assert isinstance(a3.list[1], SCons.Action.FunctionAction), a3.list[1] @@ -351,7 +351,7 @@ class ActionTestCase(unittest.TestCase): a4 = SCons.Action.Action(["x", "y"], strfunction=foo) assert isinstance(a4, SCons.Action.ListAction), a4 - assert a4.varlist is (), a4.varlist + assert a4.varlist == (), a4.varlist assert isinstance(a4.list[0], SCons.Action.CommandAction), a4.list[0] assert a4.list[0].cmd_list == "x", a4.list[0].cmd_list assert a4.list[0].strfunction == foo, a4.list[0].strfunction @@ -361,7 +361,7 @@ class ActionTestCase(unittest.TestCase): a5 = SCons.Action.Action("x\ny", strfunction=foo) assert isinstance(a5, SCons.Action.ListAction), a5 - assert a5.varlist is (), a5.varlist + assert a5.varlist == (), a5.varlist assert isinstance(a5.list[0], SCons.Action.CommandAction), a5.list[0] assert a5.list[0].cmd_list == "x", a5.list[0].cmd_list assert a5.list[0].strfunction == foo, a5.list[0].strfunction @@ -488,7 +488,7 @@ class _ActionActionTestCase(unittest.TestCase): def func(): pass try: a = SCons.Action.Action('foo', cmdstr='string', strfunction=func) - except SCons.Errors.UserError, e: + except SCons.Errors.UserError as e: s = str(e) m = 'Cannot have both strfunction and cmdstr args to Action()' assert s.find(m) != -1, 'Unexpected string: %s' % s @@ -556,7 +556,7 @@ class _ActionActionTestCase(unittest.TestCase): assert isinstance(source, list), type(source) return 9 b = SCons.Action.Action([firstfunc, execfunc, lastfunc]) - + sio = io.StringIO() sys.stdout = sio result = a("out", "in", env) @@ -699,7 +699,7 @@ class _ActionActionTestCase(unittest.TestCase): env['PRINT_CMD_LINE_FUNC'] = my_print_cmd_line a("output", "input", env) assert result == ["execfunc(['output'], ['input'])"], result - + finally: sys.stdout = save_stdout @@ -942,7 +942,7 @@ class CommandActionTestCase(unittest.TestCase): act = SCons.Action.CommandAction('xyzzy $TARGETS $SOURCES', cmdstr='cmdstr\t$TARGETS\n$SOURCES ') - + s = act.strfunction([], [], env) assert s == 'cmdstr\t\n ', s s = act.strfunction([t1], [s1], env) @@ -1241,12 +1241,12 @@ class CommandActionTestCase(unittest.TestCase): (env["foo"], env["bar"]) # The number 1 is there to make sure all args get converted to strings. - a = SCons.Action.CommandAction(["|", "$(", "$foo", "|", "$bar", - "$)", "|", "$baz", 1]) + a = SCons.Action.CommandAction(["|", "$(", "$foo", "|", "$(", "$bar", + "$)", "stuff", "$)", "|", "$baz", 1]) c = a.get_contents(target=[], source=[], env=Environment(foo = 'FFF', bar = 'BBB', baz = CmdGen)) - assert c == "| | FFF BBB 1", c + assert c == b"| | FFF BBB 1", c # Make sure that CommandActions use an Environment's # subst_target_source() method for substitution. @@ -1257,7 +1257,7 @@ class CommandActionTestCase(unittest.TestCase): c = a.get_contents(target=DummyNode('ttt'), source = DummyNode('sss'), env=SpecialEnvironment(foo = 'GGG', bar = 'CCC', baz = 'ZZZ')) - assert c == 'subst_target_source: | $( $foo | $bar $) | $baz 1', c + assert c == b'subst_target_source: | $( $foo | $( $bar $) stuff $) | $baz 1', c # We've discussed using the real target and source names in a # CommandAction's signature contents. This would have have the @@ -1274,35 +1274,35 @@ class CommandActionTestCase(unittest.TestCase): a = SCons.Action.CommandAction(["$TARGET"]) c = a.get_contents(target=t, source=s, env=env) - assert c == "t1", c + assert c == b"t1", c a = SCons.Action.CommandAction(["$TARGETS"]) c = a.get_contents(target=t, source=s, env=env) - assert c == "t1 t2 t3 t4 t5 t6", c + assert c == b"t1 t2 t3 t4 t5 t6", c a = SCons.Action.CommandAction(["${TARGETS[2]}"]) c = a.get_contents(target=t, source=s, env=env) - assert c == "t3", c + assert c == b"t3", c a = SCons.Action.CommandAction(["${TARGETS[3:5]}"]) c = a.get_contents(target=t, source=s, env=env) - assert c == "t4 t5", c + assert c == b"t4 t5", c a = SCons.Action.CommandAction(["$SOURCE"]) c = a.get_contents(target=t, source=s, env=env) - assert c == "s1", c + assert c == b"s1", c a = SCons.Action.CommandAction(["$SOURCES"]) c = a.get_contents(target=t, source=s, env=env) - assert c == "s1 s2 s3 s4 s5 s6", c + assert c == b"s1 s2 s3 s4 s5 s6", c a = SCons.Action.CommandAction(["${SOURCES[2]}"]) c = a.get_contents(target=t, source=s, env=env) - assert c == "s3", c + assert c == b"s3", c a = SCons.Action.CommandAction(["${SOURCES[3:5]}"]) c = a.get_contents(target=t, source=s, env=env) - assert c == "s4 s5", c + assert c == b"s4 s5", c class CommandGeneratorActionTestCase(unittest.TestCase): @@ -1419,7 +1419,7 @@ class CommandGeneratorActionTestCase(unittest.TestCase): ignore = 'foo', test=test) a = self.factory(f) c = a.get_contents(target=[], source=[], env=env) - assert c == "guux FFF BBB test", c + assert c == b"guux FFF BBB test", c def test_get_contents_of_function_action(self): """Test contents of a CommandGeneratorAction-generated FunctionAction @@ -1428,14 +1428,16 @@ class CommandGeneratorActionTestCase(unittest.TestCase): def LocalFunc(): pass - func_matches = [ - "0,0,0,0,(),(),(d\000\000S),(),()", - "0,0,0,0,(),(),(d\x00\x00S),(),()", - ] - + # Since the python bytecode has per version differences, we need different expected results per version + func_matches = { + (2,7) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'), + (3,5) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'), + (3,6) : bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'), + } + meth_matches = [ - "1,1,0,0,(),(),(d\000\000S),(),()", - "1,1,0,0,(),(),(d\x00\x00S),(),()", + b"1, 1, 0, 0,(),(),(d\000\000S),(),()", + b"1, 1, 0, 0,(),(),(d\x00\x00S),(),()", ] def f_global(target, source, env, for_signature): @@ -1448,11 +1450,11 @@ class CommandGeneratorActionTestCase(unittest.TestCase): a = self.factory(f_global) c = a.get_contents(target=[], source=[], env=env) - assert c in func_matches, repr(c) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected \n"+repr(func_matches[sys.version_info[:2]]) a = self.factory(f_local) c = a.get_contents(target=[], source=[], env=env) - assert c in func_matches, repr(c) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected \n"+repr(func_matches[sys.version_info[:2]]) def f_global(target, source, env, for_signature): return SCons.Action.Action(GlobalFunc, varlist=['XYZ']) @@ -1460,7 +1462,7 @@ class CommandGeneratorActionTestCase(unittest.TestCase): def f_local(target, source, env, for_signature): return SCons.Action.Action(LocalFunc, varlist=['XYZ']) - matches_foo = [x + "foo" for x in func_matches] + matches_foo = func_matches[sys.version_info[:2]] + b'foo' a = self.factory(f_global) c = a.get_contents(target=[], source=[], env=env) @@ -1533,7 +1535,8 @@ class FunctionActionTestCase(unittest.TestCase): global count count = count + 1 for t in target: - open(t, 'w').write("function1\n") + with open(t, 'w') as f: + f.write("function1\n") return 1 act = SCons.Action.FunctionAction(function1, {}) @@ -1548,7 +1551,8 @@ class FunctionActionTestCase(unittest.TestCase): class class1a(object): def __init__(self, target, source, env): - open(env['out'], 'w').write("class1a\n") + with open(env['out'], 'w') as f: + f.write("class1a\n") act = SCons.Action.FunctionAction(class1a, {}) r = act([], [], Environment(out = outfile)) @@ -1558,7 +1562,8 @@ class FunctionActionTestCase(unittest.TestCase): class class1b(object): def __call__(self, target, source, env): - open(env['out'], 'w').write("class1b\n") + with open(env['out'], 'w') as f: + f.write("class1b\n") return 2 act = SCons.Action.FunctionAction(class1b(), {}) @@ -1587,49 +1592,57 @@ class FunctionActionTestCase(unittest.TestCase): def LocalFunc(): pass - func_matches = [ - "0,0,0,0,(),(),(d\000\000S),(),()", - "0,0,0,0,(),(),(d\x00\x00S),(),()", - ] - - meth_matches = [ - "1,1,0,0,(),(),(d\000\000S),(),()", - "1,1,0,0,(),(),(d\x00\x00S),(),()", - ] + func_matches = { + (2,7) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'), + (3,5) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'), + (3,6) : bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'), + } + + meth_matches = { + (2,7) : bytearray(b'1, 1, 0, 0,(),(),(d\x00\x00S),(),()'), + (3,5) : bytearray(b'1, 1, 0, 0,(),(),(d\x00\x00S),(),()'), + (3,6) : bytearray(b'1, 1, 0, 0,(),(),(d\x00S\x00),(),()'), + } def factory(act, **kw): return SCons.Action.FunctionAction(act, kw) a = factory(GlobalFunc) c = a.get_contents(target=[], source=[], env=Environment()) - assert c in func_matches, repr(c) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(func_matches[sys.version_info[:2]]) + a = factory(LocalFunc) c = a.get_contents(target=[], source=[], env=Environment()) - assert c in func_matches, repr(c) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(func_matches[sys.version_info[:2]]) - matches_foo = [x + "foo" for x in func_matches] + matches_foo = func_matches[sys.version_info[:2]] + b'foo' a = factory(GlobalFunc, varlist=['XYZ']) c = a.get_contents(target=[], source=[], env=Environment()) - assert c in func_matches, repr(c) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(func_matches[sys.version_info[:2]]) + # assert c in func_matches, repr(c) + c = a.get_contents(target=[], source=[], env=Environment(XYZ='foo')) - assert c in matches_foo, repr(c) + assert c == matches_foo, repr(c) ##TODO: is this set of tests still needed? # Make sure a bare string varlist works a = factory(GlobalFunc, varlist='XYZ') c = a.get_contents(target=[], source=[], env=Environment()) - assert c in func_matches, repr(c) + # assert c in func_matches, repr(c) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(func_matches[sys.version_info[:2]]) + + c = a.get_contents(target=[], source=[], env=Environment(XYZ='foo')) assert c in matches_foo, repr(c) class Foo(object): def get_contents(self, target, source, env): - return 'xyzzy' + return b'xyzzy' a = factory(Foo()) c = a.get_contents(target=[], source=[], env=Environment()) - assert c == 'xyzzy', repr(c) + assert c == b'xyzzy', repr(c) class LocalClass(object): def LocalMethod(self): @@ -1637,7 +1650,7 @@ class FunctionActionTestCase(unittest.TestCase): lc = LocalClass() a = factory(lc.LocalMethod) c = a.get_contents(target=[], source=[], env=Environment()) - assert c in meth_matches, repr(c) + assert c == meth_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(meth_matches[sys.version_info[:2]]) def test_strfunction(self): """Test the FunctionAction.strfunction() method @@ -1710,17 +1723,20 @@ class ListActionTestCase(unittest.TestCase): cmd2 = r'%s %s %s syzygy' % (_python_, act_py, outfile) def function2(target, source, env): - open(env['out'], 'a').write("function2\n") + with open(env['out'], 'a') as f: + f.write("function2\n") return 0 class class2a(object): def __call__(self, target, source, env): - open(env['out'], 'a').write("class2a\n") + with open(env['out'], 'a') as f: + f.write("class2a\n") return 0 class class2b(object): def __init__(self, target, source, env): - open(env['out'], 'a').write("class2b\n") + with open(env['out'], 'a') as f: + f.write("class2b\n") act = SCons.Action.ListAction([cmd2, function2, class2a(), class2b]) r = act([], [], Environment(out = outfile)) assert isinstance(r.status, class2b), r.status @@ -1740,7 +1756,7 @@ class ListActionTestCase(unittest.TestCase): "z"]) c = a.get_contents(target=[], source=[], env=Environment(s = self)) assert self.foo==1, self.foo - assert c == "xyz", c + assert c == b"xyz", c class LazyActionTestCase(unittest.TestCase): def test___init__(self): @@ -1791,7 +1807,7 @@ class LazyActionTestCase(unittest.TestCase): a = SCons.Action.Action("${FOO}") env = Environment(FOO = [["This", "is", "a", "test"]]) c = a.get_contents(target=[], source=[], env=env) - assert c == "This is a test", c + assert c == b"This is a test", c def test_get_contents_of_function_action(self): """Test fetching the contents of a lazy-evaluation FunctionAction @@ -1800,14 +1816,16 @@ class LazyActionTestCase(unittest.TestCase): def LocalFunc(): pass - func_matches = [ - "0,0,0,0,(),(),(d\000\000S),(),()", - "0,0,0,0,(),(),(d\x00\x00S),(),()", - ] - + + func_matches = { + (2,7) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'), + (3,5) : bytearray(b'0, 0, 0, 0,(),(),(d\x00\x00S),(),()'), + (3,6) : bytearray(b'0, 0, 0, 0,(),(),(d\x00S\x00),(),()'), + } + meth_matches = [ - "1,1,0,0,(),(),(d\000\000S),(),()", - "1,1,0,0,(),(),(d\x00\x00S),(),()", + b"1, 1, 0, 0,(),(),(d\000\000S),(),()", + b"1, 1, 0, 0,(),(),(d\x00\x00S),(),()", ] def factory(act, **kw): @@ -1818,22 +1836,28 @@ class LazyActionTestCase(unittest.TestCase): env = Environment(FOO = factory(GlobalFunc)) c = a.get_contents(target=[], source=[], env=env) - assert c in func_matches, repr(c) + # assert c in func_matches, "Got\n"+repr(c)+"\nExpected one of \n"+"\n".join([repr(f) for f in func_matches]) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(func_matches[sys.version_info[:2]]) + + env = Environment(FOO = factory(LocalFunc)) c = a.get_contents(target=[], source=[], env=env) - assert c in func_matches, repr(c) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(func_matches[sys.version_info[:2]]) + + # matches_foo = [x + b"foo" for x in func_matches] + matches_foo = func_matches[sys.version_info[:2]] + b'foo' - matches_foo = [x + "foo" for x in func_matches] env = Environment(FOO = factory(GlobalFunc, varlist=['XYZ'])) c = a.get_contents(target=[], source=[], env=env) - assert c in func_matches, repr(c) + assert c == func_matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(func_matches[sys.version_info[:2]]) env['XYZ'] = 'foo' c = a.get_contents(target=[], source=[], env=env) assert c in matches_foo, repr(c) + class ActionCallerTestCase(unittest.TestCase): def test___init__(self): """Test creation of an ActionCaller""" @@ -1850,25 +1874,23 @@ class ActionCallerTestCase(unittest.TestCase): def LocalFunc(): pass - matches = [ - "d\000\000S", - "d\x00\x00S" - ] + + matches = { + (2,7) : b'd\x00\x00S', + (3,5) : b'd\x00\x00S', + (3,6) : b'd\x00S\x00', + } + af = SCons.Action.ActionFactory(GlobalFunc, strfunc) ac = SCons.Action.ActionCaller(af, [], {}) c = ac.get_contents([], [], Environment()) - assert c in matches, repr(c) + assert c == matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(matches[sys.version_info[:2]]) af = SCons.Action.ActionFactory(LocalFunc, strfunc) ac = SCons.Action.ActionCaller(af, [], {}) c = ac.get_contents([], [], Environment()) - assert c in matches, repr(c) - - matches = [ - 'd\000\000S', - "d\x00\x00S" - ] + assert c == matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(matches[sys.version_info[:2]]) class LocalActFunc(object): def __call__(self): @@ -1877,23 +1899,25 @@ class ActionCallerTestCase(unittest.TestCase): af = SCons.Action.ActionFactory(GlobalActFunc(), strfunc) ac = SCons.Action.ActionCaller(af, [], {}) c = ac.get_contents([], [], Environment()) - assert c in matches, repr(c) + assert c == matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(matches[sys.version_info[:2]]) af = SCons.Action.ActionFactory(LocalActFunc(), strfunc) ac = SCons.Action.ActionCaller(af, [], {}) c = ac.get_contents([], [], Environment()) - assert c in matches, repr(c) + assert c == matches[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected one of \n"+repr(matches[sys.version_info[:2]]) matches = [ - "<built-in function str>", - "<type 'str'>", + b"<built-in function str>", + b"<type 'str'>", ] af = SCons.Action.ActionFactory(str, strfunc) ac = SCons.Action.ActionCaller(af, [], {}) c = ac.get_contents([], [], Environment()) assert c == "<built-in function str>" or \ - c == "<type 'str'>", repr(c) + c == "<type 'str'>" or \ + c == "<class 'str'>", repr(c) + # ^^ class str for python3 def test___call__(self): """Test calling an ActionCaller""" @@ -1999,21 +2023,85 @@ class ActionCompareTestCase(unittest.TestCase): especially two builders that can generate the same suffix, where one of the builders has a suffix dictionary with a None key.""" - + foo = SCons.Builder.Builder(action = '$FOO', suffix = '.foo') bar = SCons.Builder.Builder(action = {}, suffix={None:'.bar'}) bar.add_action('.cow', "$MOO") dog = SCons.Builder.Builder(suffix = '.bar') - + env = Environment( BUILDERS = {'FOO' : foo, 'BAR' : bar, 'DOG' : dog} ) - + assert foo.get_name(env) == 'FOO', foo.get_name(env) assert bar.get_name(env) == 'BAR', bar.get_name(env) assert dog.get_name(env) == 'DOG', dog.get_name(env) +class TestClass(object): + """A test class used by ObjectContentsTestCase.test_object_contents""" + def __init__(self): + self.a = "a" + self.b = "b" + def method(self, arg): + pass + + +class ObjectContentsTestCase(unittest.TestCase): + + def test_function_contents(self): + """Test that Action._function_contents works""" + + def func1(a, b, c): + """A test function""" + return a + + # Since the python bytecode has per version differences, we need different expected results per version + expected = { + (2,7) : bytearray(b'3, 3, 0, 0,(),(),(|\x00\x00S),(),()'), + (3,5) : bytearray(b'3, 3, 0, 0,(),(),(|\x00\x00S),(),()'), + (3,6) : bytearray(b'3, 3, 0, 0,(),(),(|\x00S\x00),(),()'), + } + + c = SCons.Action._function_contents(func1) + assert c == expected[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected \n"+"\n"+repr(expected[sys.version_info[:2]]) + + + def test_object_contents(self): + """Test that Action._object_contents works""" + + # See definition above + o = TestClass() + c = SCons.Action._object_contents(o) + + # c = SCons.Action._object_instance_content(o) + + # Since the python bytecode has per version differences, we need different expected results per version + expected = { + (2,7): bytearray(b"{TestClass:__main__}[[[(<type \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<type \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01\x00|\x00\x00_\x00\x00d\x02\x00|\x00\x00_\x01\x00d\x00\x00S),(),(),2, 2, 0, 0,(),(),(d\x00\x00S),(),()}}{{{a=a,b=b}}}"), + (3,5): bytearray(b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01\x00|\x00\x00_\x00\x00d\x02\x00|\x00\x00_\x01\x00d\x00\x00S),(),(),2, 2, 0, 0,(),(),(d\x00\x00S),(),()}}{{{a=a,b=b}}}"), + (3,6): bytearray(b"{TestClass:__main__}[[[(<class \'object\'>, ()), [(<class \'__main__.TestClass\'>, (<class \'object\'>,))]]]]{{1, 1, 0, 0,(a,b),(a,b),(d\x01|\x00_\x00d\x02|\x00_\x01d\x00S\x00),(),(),2, 2, 0, 0,(),(),(d\x00S\x00),(),()}}{{{a=a,b=b}}}"), + } + + assert c == expected[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected \n"+"\n"+repr(expected[sys.version_info[:2]]) + + def test_code_contents(self): + """Test that Action._code_contents works""" + + code = compile("print('Hello, World!')", '<string>', 'exec') + c = SCons.Action._code_contents(code) + + # Since the python bytecode has per version differences, we need different expected results per version + expected = { + (2,7) : bytearray(b'0, 0, 0, 0,(N.),(),(d\x00\x00GHd\x01\x00S)'), + (3,5) : bytearray(b'0, 0, 0, 0,(N.),(print),(e\x00\x00d\x00\x00\x83\x01\x00\x01d\x01\x00S)'), + (3,6) : bytearray(b'0, 0, 0, 0,(N.),(print),(e\x00d\x00\x83\x01\x01\x00d\x01S\x00)'), + } + + assert c == expected[sys.version_info[:2]], "Got\n"+repr(c)+"\nExpected \n"+"\n"+expected[sys.version_info[:2]] + + + if __name__ == "__main__": suite = unittest.TestSuite() tclasses = [ _ActionActionTestCase, @@ -2025,13 +2113,17 @@ if __name__ == "__main__": LazyActionTestCase, ActionCallerTestCase, ActionFactoryTestCase, - ActionCompareTestCase ] + ActionCompareTestCase, + ObjectContentsTestCase ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') suite.addTests(list(map(tclass, names))) TestUnit.run(suite) + # Swap this for above to debug otherwise you can't run individual tests as TestUnit is swallowing arguments + # unittest.main() + # Local Variables: # tab-width:4 # indent-tabs-mode:nil |