summaryrefslogtreecommitdiff
path: root/src/engine/SCons/UtilTests.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/UtilTests.py')
-rw-r--r--src/engine/SCons/UtilTests.py59
1 files changed, 33 insertions, 26 deletions
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index 9ce3d23..1df4069 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.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/UtilTests.py rel_2.5.1:3735:9dc6cee5c168 2016/11/03 14:02:02 bdbaddog"
+__revision__ = "src/engine/SCons/UtilTests.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
import SCons.compat
@@ -186,26 +186,31 @@ class UtilTestCase(unittest.TestCase):
try:
node, expect, withtags = self.tree_case_1()
- sys.stdout = io.StringIO()
+ if sys.version_info.major < 3:
+ IOStream = io.BytesIO
+ else:
+ IOStream = io.StringIO
+
+ sys.stdout = IOStream()
print_tree(node, get_children)
actual = sys.stdout.getvalue()
assert expect == actual, (expect, actual)
- sys.stdout = io.StringIO()
+ sys.stdout = IOStream()
print_tree(node, get_children, showtags=1)
actual = sys.stdout.getvalue()
assert withtags == actual, (withtags, actual)
-
+
# Test that explicitly setting prune to zero works
# the same as the default (see above)
node, expect, withtags = self.tree_case_2(prune=0)
-
- sys.stdout = io.StringIO()
+
+ sys.stdout = IOStream()
print_tree(node, get_children, 0)
actual = sys.stdout.getvalue()
assert expect == actual, (expect, actual)
-
- sys.stdout = io.StringIO()
+
+ sys.stdout = IOStream()
print_tree(node, get_children, 0, showtags=1)
actual = sys.stdout.getvalue()
assert withtags == actual, (withtags, actual)
@@ -213,7 +218,7 @@ class UtilTestCase(unittest.TestCase):
# Test output with prune=1
node, expect, withtags = self.tree_case_2(prune=1)
- sys.stdout = io.StringIO()
+ sys.stdout = IOStream()
print_tree(node, get_children, 1)
actual = sys.stdout.getvalue()
assert expect == actual, (expect, actual)
@@ -222,12 +227,12 @@ class UtilTestCase(unittest.TestCase):
# again. This wasn't possible in version 2.4.1 and earlier
# due to a bug in print_tree (visited was set to {} as default
# parameter)
- sys.stdout = io.StringIO()
+ sys.stdout = IOStream()
print_tree(node, get_children, 1)
actual = sys.stdout.getvalue()
assert expect == actual, (expect, actual)
- sys.stdout = io.StringIO()
+ sys.stdout = IOStream()
print_tree(node, get_children, 1, showtags=1)
actual = sys.stdout.getvalue()
assert withtags == actual, (withtags, actual)
@@ -237,7 +242,11 @@ class UtilTestCase(unittest.TestCase):
def test_is_Dict(self):
assert is_Dict({})
assert is_Dict(UserDict())
- assert is_Dict(os.environ)
+
+ # os.environ is not a dictionary in python 3
+ if sys.version_info < (3,0):
+ assert is_Dict(os.environ)
+
try:
class mydict(dict):
pass
@@ -249,7 +258,7 @@ class UtilTestCase(unittest.TestCase):
assert not is_Dict(())
assert not is_Dict("")
if HasUnicode:
- exec "assert not is_Dict(u'')"
+ exec("assert not is_Dict(u'')")
def test_is_List(self):
assert is_List([])
@@ -265,12 +274,12 @@ class UtilTestCase(unittest.TestCase):
assert not is_List({})
assert not is_List("")
if HasUnicode:
- exec "assert not is_List(u'')"
+ exec("assert not is_List(u'')")
def test_is_String(self):
assert is_String("")
if HasUnicode:
- exec "assert is_String(u'')"
+ exec("assert is_String(u'')")
assert is_String(UserString(''))
try:
class mystr(str):
@@ -296,7 +305,7 @@ class UtilTestCase(unittest.TestCase):
assert not is_Tuple({})
assert not is_Tuple("")
if HasUnicode:
- exec "assert not is_Tuple(u'')"
+ exec("assert not is_Tuple(u'')")
def test_to_String(self):
"""Test the to_String() method."""
@@ -343,10 +352,10 @@ class UtilTestCase(unittest.TestCase):
os.mkdir(sub2_xxx_exe)
test.write(sub3_xxx_exe, "\n")
- os.chmod(sub3_xxx_exe, 0777)
+ os.chmod(sub3_xxx_exe, 0o777)
test.write(sub4_xxx_exe, "\n")
- os.chmod(sub4_xxx_exe, 0777)
+ os.chmod(sub4_xxx_exe, 0o777)
env_path = os.environ['PATH']
@@ -723,7 +732,7 @@ class UtilTestCase(unittest.TestCase):
def test_LogicalLines(self):
"""Test the LogicalLines class"""
- content = r"""
+ content = u"""
foo \
bar \
baz
@@ -732,9 +741,7 @@ bling \
bling \ bling
bling
"""
- # Python 2.7 and beyond require unicode strings.
- fobj = io.StringIO(unicode(content))
-
+ fobj = io.StringIO(content)
lines = LogicalLines(fobj).readlines()
assert lines == [
'\n',
@@ -746,8 +753,8 @@ bling
def test_intern(self):
s1 = silent_intern("spam")
- # Python 3.x does not have a unicode() global function
- if sys.version[0] == '2':
+ # TODO: Python 3.x does not have a unicode() global function
+ if sys.version[0] == '2':
s2 = silent_intern(unicode("unicode spam"))
s3 = silent_intern(42)
s4 = silent_intern("spam")
@@ -760,7 +767,7 @@ class MD5TestCase(unittest.TestCase):
"""Test collecting a list of signatures into a new signature value
"""
s = list(map(MD5signature, ('111', '222', '333')))
-
+
assert '698d51a19d8a121ce581499d7b701668' == MD5collect(s[0:1])
assert '8980c988edc2c78cc43ccb718c06efd5' == MD5collect(s[0:2])
assert '53fd88c84ff8a285eb6e0a687e55b8c7' == MD5collect(s)