Commits

dirkbaechle  committed 6987c40

- extended the must_contain* methods of the test framework, such that they all support user-defined find/search functions
- relaxed several of the regex comparisons for better cross-platform compatibility

  • Participants
  • Parent commits ff3917f

Comments (0)

Files changed (12)

File QMTest/TestCommon.py

             print "Unwritable files: `%s'" % "', `".join(unwritable)
         self.fail_test(missing + unwritable)
 
-    def must_contain(self, file, required, mode = 'rb'):
+    def must_contain(self, file, required, mode = 'rb', find = None):
         """Ensures that the specified file contains the required text.
         """
         file_contents = self.read(file, mode)
-        contains = (file_contents.find(required) != -1)
+        if find is None:
+            def find(o, l):
+                try:
+                    return o.index(l)
+                except ValueError:
+                    return None
+        contains = find(file_contents, required)
         if not contains:
             print "File `%s' does not contain required string." % file
             print self.banner('Required string ')
                 except ValueError:
                     return None
         missing = []
+        if is_List(output):
+            output = '\n'.join(output)
+
         for line in lines:
             if find(output, line) is None:
                 missing.append(line)
         sys.stdout.flush()
         self.fail_test()
 
-    def must_contain_lines(self, lines, output, title=None):
+    def must_contain_lines(self, lines, output, title=None, find = None):
         # Deprecated; retain for backwards compatibility.
-        return self.must_contain_all_lines(output, lines, title)
+        return self.must_contain_all_lines(output, lines, title, find)
 
     def must_exist(self, *files):
         """Ensures that the specified file(s) must exist.  An individual
             self.diff(expect, file_contents, 'contents ')
             raise
 
-    def must_not_contain(self, file, banned, mode = 'rb'):
+    def must_not_contain(self, file, banned, mode = 'rb', find = None):
         """Ensures that the specified file doesn't contain the banned text.
         """
         file_contents = self.read(file, mode)
-        contains = (file_contents.find(banned) != -1)
+        if find is None:
+            def find(o, l):
+                try:
+                    return o.index(l)
+                except ValueError:
+                    return None
+        contains = find(file_contents, banned)
         if contains:
             print "File `%s' contains banned string." % file
             print self.banner('Banned string ')
             sys.stdout.write(output)
             self.fail_test()
 
-    def must_not_contain_lines(self, lines, output, title=None):
-        return self.must_not_contain_any_line(output, lines, title)
+    def must_not_contain_lines(self, lines, output, title=None, find=None):
+        return self.must_not_contain_any_line(output, lines, title, find)
 
     def must_not_exist(self, *files):
         """Ensures that the specified file(s) must not exist.

File QMTest/TestSCons.py

         str = str.replace(c, '\\' + c)
     return str
 
+#
+# Helper functions that we use as a replacement to the default re.match
+# when searching for special strings in stdout/stderr.
+#
+def search_re(out, l):
+    """ Search the regular expression 'l' in the output 'out'
+        and return the start index when successful.
+    """
+    m = re.search(l, out)
+    if m:
+        return m.start()
+    
+    return None
 
+def search_re_in_list(out, l):
+    """ Search the regular expression 'l' in each line of
+        the given string list 'out' and return the line's index
+        when successful.
+    """
+    for idx, o in enumerate(out):
+        m = re.search(l, o)
+        if m:
+            return idx
+    
+    return None
+
+#
+# Helpers for handling Python version numbers
+#
 def python_version_string():
     return sys.version.split()[0]
 

File test/Delete.py

     "No such file or directory",
     "The system cannot find the file specified",
     "The system cannot find the path specified",
+    "Das System kann die angegebene Datei nicht finden",
 ]
 
 test.must_contain_any_line(test.stderr(), fail_strings)

File test/Errors/execute-a-directory.py

 """
 
 unrecognized = """\
-'%s' is not recognized as an internal or external command,
+'.+' is not recognized as an internal or external command,
 operable program or batch file.
-scons: *** [%s] Error 1
+scons: \*\*\* \[%s\] Error 1
 """
 
 unspecified = """\
 The name specified is not recognized as an
 internal or external command, operable program or batch file.
-scons: *** [%s] Error 1
+scons: \*\*\* \[%s\] Error 1
 """
 
 cannot_execute = """\
-%s: cannot execute
-scons: *** [%s] Error %s
-"""
-
-Permission_denied = """\
-%s: Permission denied
-scons: *** [%s] Error %s
+(sh: )*.+: cannot execute
+scons: \*\*\* \[%s\] Error %s
 """
 
 permission_denied = """\
-%s: permission denied
-scons: *** [%s] Error %s
+.+: (p|P)ermission denied
+scons: \*\*\* \[%s\] Error %s
 """
 
 is_a_directory = """\
-%s: is a directory
-scons: *** [%s] Error %s
+.+: (i|I)s a directory
+scons: \*\*\* \[%s\] Error %s
 """
 
-Is_a_directory = """\
-%s: Is a directory
-scons: *** [%s] Error %s
+konnte_nicht_gefunden_werden = """\
+Der Befehl ".+" ist entweder falsch geschrieben oder
+konnte nicht gefunden werden.
+scons: \*\*\* \[%s\] Error %s
 """
 
 test.description_set("Incorrect STDERR:\n%s\n" % test.stderr())
 if os.name == 'nt':
     errs = [
         bad_command,
-        unrecognized % (test.workdir, 'f3'),
+        unrecognized % 'f3',
+        konnte_nicht_gefunden_werden % ('f3', 1),
         unspecified % 'f3'
     ]
-    test.fail_test(not test.stderr() in errs)
 elif sys.platform.find('sunos') != -1:
     errs = [
-        cannot_execute % ('sh: %s' % test.workdir, 'f3', 1),
+        cannot_execute % ('f3', 1),
     ]
-    test.fail_test(not test.stderr() in errs)
 else:
     errs = [
-        cannot_execute % (not_executable, 'f3', 126),
-        is_a_directory % (test.workdir, 'f3', 126),
-        Is_a_directory % (test.workdir, 'f3', 126),
-        Permission_denied % (test.workdir, 'f3', 126),
+        cannot_execute % ('f3', 126),
+        is_a_directory % ('f3', 126),
+        permission_denied % ('f3', 126),
     ]
-    test.must_contain_any_line(test.stderr(), errs)
+
+test.must_contain_any_line(test.stderr(), errs, find=TestSCons.search_re)
 
 test.pass_test()
 

File test/Errors/non-executable-file.py

 """
 
 unrecognized = """\
-'%s' is not recognized as an internal or external command,
+'.+' is not recognized as an internal or external command,
 operable program or batch file.
-scons: *** [%s] Error 1
+scons: \*\*\* \[%s\] Error 1
 """
 
 unspecified = """\
 The name specified is not recognized as an
 internal or external command, operable program or batch file.
-scons: *** [%s] Error 1
+scons: \*\*\* \[%s\] Error 1
 """
 
 cannot_execute = """\
-%s: cannot execute
-scons: *** [%s] Error %s
-"""
-
-Permission_denied = """\
-%s: Permission denied
-scons: *** [%s] Error %s
+(sh: )*.+: cannot execute
+scons: \*\*\* \[%s\] Error %s
 """
 
 permission_denied = """\
-%s: permission denied
-scons: *** [%s] Error %s
+.+: (p|P)ermission denied
+scons: \*\*\* \[%s\] Error %s
+"""
+
+konnte_nicht_gefunden_werden = """\
+Der Befehl ".+" ist entweder falsch geschrieben oder
+konnte nicht gefunden werden.
+scons: \*\*\* \[%s\] Error %s
 """
 
 test.write('SConstruct', r"""
 if os.name == 'nt':
     errs = [
         bad_command,
-        unrecognized % (not_executable, 'f1'),
+        unrecognized % 'f1',
+        konnte_nicht_gefunden_werden % ('f1', 1),
         unspecified % 'f1'
     ]
-    test.fail_test(not test.stderr() in errs)
 elif sys.platform.find('sunos') != -1:
     errs = [
-        cannot_execute % ('sh: %s' % not_executable, 'f1', 1),
+        cannot_execute % ('f1', 1),
     ]
-    test.fail_test(not test.stderr() in errs)
 else:
     errs = [
-        cannot_execute % (not_executable, 'f1', 126),
-        Permission_denied % (not_executable, 'f1', 126),
-        permission_denied % (not_executable, 'f1', 126),
+        cannot_execute % ('f1', 126),
+        permission_denied % ('f1', 126),
     ]
-    test.must_contain_any_line(test.stderr(), errs)
+
+test.must_contain_any_line(test.stderr(), errs, find=TestSCons.search_re)
 
 test.pass_test()
 

File test/Errors/nonexistent-executable.py

          stderr = None,
          status = 2)
 
-bad_command = """\
-Bad command or file name
-"""
-
-unrecognized = """\
-'%s' is not recognized as an internal or external command,
-operable program or batch file.
-scons: *** [%s] Error 1
-"""
-
-unspecified = """\
-The name specified is not recognized as an
-internal or external command, operable program or batch file.
-scons: *** [%s] Error 1
-"""
-
-not_found_1_space = """\
-sh: %s: not found
-scons: *** [%s] Error %s
-"""
-
-not_found_2_spaces = """\
-sh: %s:  not found
-scons: *** [%s] Error %s
-"""
-
-No_such = """\
-%s: No such file or directory
-scons: *** [%s] Error %s
-"""
+bad_command = """Bad command or file name"""
+unrecognized = r"""'.+' is not recognized as an internal or external command,\s+operable program or batch file.\sscons: \*\*\* \[%s\] Error 1"""
+unspecified = r"""The name specified is not recognized as an\s+internal or external command, operable program or batch file.\s+scons: \*\*\* \[%s\] Error 1"""
+not_found_space = r"""sh: (\d: )*.+: \s*not found\s+scons: \*\*\* \[%s\] Error %s"""
+No_such = r""".+: No such file or directory\s+scons: \*\*\* \[%s\] Error %s"""
+konnte_nicht_gefunden_werden = r"""Der Befehl ".+" ist entweder falsch geschrieben oder\s+konnte nicht gefunden werden.\s+scons: \*\*\* \[%s\] Error %s"""
 
 test.description_set("Incorrect STDERR:\n%s\n" % test.stderr())
 if os.name == 'nt':
     errs = [
         bad_command,
-        unrecognized % (no_such_file, 'f1'),
+        unrecognized % 'f1',
+        konnte_nicht_gefunden_werden % ('f1', 1),
         unspecified % 'f1'
     ]
-    test.fail_test(not test.stderr() in errs)
 elif sys.platform.find('sunos') != -1:
     errs = [
-        not_found_1_space % (no_such_file, 'f1', 1),
+        not_found_space % ('f1', 1),
     ]
-    test.fail_test(not test.stderr() in errs)
 else:
     errs = [
-        not_found_1_space % (no_such_file, 'f1', 1),
-        not_found_2_spaces % (no_such_file, 'f1', 1),
-        not_found_1_space % (no_such_file, 'f1', 127),
-        No_such % (no_such_file, 'f1', 127),
+        not_found_space % ('f1', 1),
+        not_found_space % ('f1', 127),
+        No_such % ('f1', 127),
     ]
-    test.must_contain_any_line(test.stderr(), errs)
+
+test.must_contain_any_line(test.stderr(), errs, find=TestSCons.search_re)
 
 test.pass_test()
 

File test/Execute.py

 
 import sys
 if sys.platform == 'win32':
-    expect = """\
-scons: *** Error 1
-scons: *** Error 2
-scons: *** nonexistent.in/*.*: The system cannot find the path specified
-"""
+    expect = r"""scons: \*\*\* Error 1
+scons: \*\*\* Error 2
+scons: \*\*\* nonexistent.in/\*\.\*: (The system cannot find the path specified|Das System kann den angegebenen Pfad nicht finden)"""
 else:
-    expect = """\
-scons: *** Error 1
-scons: *** Error 2
-scons: *** nonexistent.in: No such file or directory
-"""
+    expect = r"""scons: \*\*\* Error 1
+scons: \*\*\* Error 2
+scons: \*\*\* nonexistent\.in: No such file or directory"""
 
-test.run(arguments = '.', stderr=expect)
+test.run(arguments = '.', stdout = None, stderr = None)
+
+test.must_contain_all_lines(test.stderr(), expect.splitlines(), find=TestSCons.search_re)
 
 test.must_match('a.out', "a.in\n")
 test.must_match('b.out', "b.in\n")

File test/Install/Install.py

 expect =  [
     "Permission denied",
     "The process cannot access the file because it is being used by another process",
+    "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird",
 ]
 
 test.run(chdir = 'work', arguments = f1_out, stderr=None, status=2)

File test/Interactive/shell.py

 scons.send("\n")
 
 if sys.platform == 'win32':
-    no_such_error = "'no_such_command' is not recognized as an internal or external command,\noperable program or batch file."
+    no_such_error = r"('no_such_command' is not recognized as an internal or external command,\s+operable program or batch file\.|Der Befehl \"no_such_command\" ist entweder falsch geschrieben oder\s+konnte nicht gefunden werden\.)"
 else:
     no_such_error = 'scons: no_such_command: No such file or directory'
 
 expect_stdout = """\
-scons>>> Copy("foo.out", "foo.in")
-Touch("1")
+scons>>> Copy\("foo.out", "foo.in"\)
+Touch\("1"\)
 scons>>> hello from shell_command.py
-scons>>> !%(_python_)s %(_shell_command_py_)s
+scons>>> ![^"]+ ".*"
 hello from shell_command.py
 scons>>> hello from shell_command.py
-scons>>> shell %(_python_)s %(_shell_command_py_)s
+scons>>> shell [^"]+ ".*"
 hello from shell_command.py
 scons>>> hello from shell_command.py
-scons>>> sh %(_python_)s %(_shell_command_py_)s
+scons>>> sh [^"]+ ".*"
 hello from shell_command.py
 scons>>> %(no_such_error)s
 scons>>> !no_such_command arg1 arg2
 scons>>> 
 """ % locals()
 
-test.finish(scons, stdout = expect_stdout)
+test.finish(scons, stdout = None)
 
-
+test.must_contain_all_lines(test.stdout(), expect_stdout.splitlines(), find=TestSCons.search_re)
 
 test.pass_test()
 

File test/Object.py

 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import sys
 import TestSCons
 
-if sys.platform == 'win32':
-    _obj = '.obj'
-else:
-    _obj = '.o'
+_obj = TestSCons._obj
 
 test = TestSCons.TestSCons()
 

File test/Repository/StaticLibrary.py

 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os.path
-import sys
 import TestSCons
 
-if sys.platform == 'win32':
-    _obj = '.obj'
-    _exe = '.exe'
-else:
-    _obj = '.o'
-    _exe = ''
-
-
+_obj = TestSCons._obj
+_exe = TestSCons._exe
 
 test = TestSCons.TestSCons()
 

File test/scons-time/func/file.py

 set key bottom left
 set label 3 "label 1.5" at 0.5,0.5 right
 set label 4 "label 1.6" at 0.6,0.4 right
-plot '-' title "Startup" with lines lt 1, \
-     '-' notitle with lines lt 7, \
-     '-' title "label 1.5" with lines lt 7, \
+plot '-' title "Startup" with lines lt 1, \\
+     '-' notitle with lines lt 7, \\
+     '-' title "label 1.5" with lines lt 7, \\
      '-' title "label 1.6" with lines lt 7
 # Startup
 1 0.000
-2 0.000
+2 0.\d*
 e
 1.4 0
 1.4 1
 e
 """
 
-test.run(arguments = 'func --file st2.conf --fmt gnuplot', stdout = expect2)
+test.run(arguments = 'func --file st2.conf --fmt gnuplot')
 
+test.must_contain_exactly_lines(test.stdout(), expect2, find=TestSCons.search_re_in_list)
 
 test.pass_test()