summaryrefslogtreecommitdiff
path: root/src/engine/SCons/Variables/VariablesTests.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/Variables/VariablesTests.py')
-rw-r--r--src/engine/SCons/Variables/VariablesTests.py44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/engine/SCons/Variables/VariablesTests.py b/src/engine/SCons/Variables/VariablesTests.py
index dc507ce..7712bb4 100644
--- a/src/engine/SCons/Variables/VariablesTests.py
+++ b/src/engine/SCons/Variables/VariablesTests.py
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2001 - 2017 The SCons Foundation
+# Copyright (c) 2001 - 2019 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,17 +21,17 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Variables/VariablesTests.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
+__revision__ = "src/engine/SCons/Variables/VariablesTests.py 103260fce95bf5db1c35fb2371983087d85dd611 2019-07-13 18:25:30 bdbaddog"
import sys
import unittest
import TestSCons
-import TestUnit
import SCons.Variables
import SCons.Subst
import SCons.Warnings
+from SCons.Util import cmp
class Environment(object):
@@ -49,12 +49,6 @@ class Environment(object):
return key in self.dict
-def cmp(a, b):
- """
- Define cmp because it's no longer available in python3
- Works under python 2 as well
- """
- return (a > b) - (a < b)
def check(key, value, env):
@@ -65,7 +59,9 @@ def check(key, value, env):
def checkSave(file, expected):
gdict = {}
ldict = {}
- exec(open(file, 'r').read(), gdict, ldict)
+ with open(file, 'r') as f:
+ exec(f.read(), gdict, ldict)
+
assert expected == ldict, "%s\n...not equal to...\n%s" % (expected, ldict)
class VariablesTestCase(unittest.TestCase):
@@ -492,9 +488,29 @@ B: b - alpha test
default: 42
actual: 54
"""
+
+ expectBackwards = """
+B: b - alpha test
+ default: 42
+ actual: 54
+
+ANSWER: THE answer to THE question
+ default: 42
+ actual: 54
+
+A: a - alpha test
+ default: 42
+ actual: 54
+"""
text = opts.GenerateHelpText(env, sort=cmp)
assert text == expectAlpha, text
+ textBool = opts.GenerateHelpText(env, sort=True)
+ assert text == expectAlpha, text
+
+ textBackwards = opts.GenerateHelpText(env, sort=lambda x, y: cmp(y, x))
+ assert textBackwards == expectBackwards, "Expected:\n%s\nGot:\n%s\n"%(textBackwards, expectBackwards)
+
def test_FormatVariableHelpText(self):
"""Test generating custom format help text"""
opts = SCons.Variables.Variables()
@@ -675,13 +691,7 @@ class UnknownVariablesTestCase(unittest.TestCase):
if __name__ == "__main__":
- suite = unittest.TestSuite()
- tclasses = [ VariablesTestCase,
- UnknownVariablesTestCase ]
- for tclass in tclasses:
- names = unittest.getTestCaseNames(tclass, 'test_')
- suite.addTests(list(map(tclass, names)))
- TestUnit.run(suite)
+ unittest.main()
# Local Variables:
# tab-width:4