[llvm] r187860 - [lit] Use modern absolute/relative import style.

Daniel Dunbar daniel at zuster.org
Tue Aug 6 20:23:12 PDT 2013


Author: ddunbar
Date: Tue Aug  6 22:23:12 2013
New Revision: 187860

URL: http://llvm.org/viewvc/llvm-project?rev=187860&view=rev
Log:
[lit] Use modern absolute/relative import style.

Modified:
    llvm/trunk/utils/lit/lit/LitConfig.py
    llvm/trunk/utils/lit/lit/ShUtil.py
    llvm/trunk/utils/lit/lit/TestFormats.py
    llvm/trunk/utils/lit/lit/TestRunner.py
    llvm/trunk/utils/lit/lit/__init__.py
    llvm/trunk/utils/lit/lit/main.py

Modified: llvm/trunk/utils/lit/lit/LitConfig.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/LitConfig.py?rev=187860&r1=187859&r2=187860&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/LitConfig.py (original)
+++ llvm/trunk/utils/lit/lit/LitConfig.py Tue Aug  6 22:23:12 2013
@@ -1,3 +1,11 @@
+from __future__ import absolute_import
+import os
+
+import lit.Test
+import lit.TestFormats
+import lit.TestingConfig
+import lit.Util
+
 class LitConfig:
     """LitConfig - Configuration data for a 'lit' test runner instance, shared
     across all tests.
@@ -9,13 +17,13 @@ class LitConfig:
     """
 
     # Provide access to Test module.
-    import Test
+    Test = lit.Test
 
     # Provide access to built-in formats.
-    import TestFormats as formats
+    formats = lit.TestFormats
 
     # Provide access to built-in utility functions.
-    import Util as util
+    util = lit.Util
 
     def __init__(self, progname, path, quiet,
                  useValgrind, valgrindLeakCheck, valgrindArgs,
@@ -58,21 +66,19 @@ class LitConfig:
     def load_config(self, config, path):
         """load_config(config, path) - Load a config object from an alternate
         path."""
-        from TestingConfig import TestingConfig
         if self.debug:
             self.note('load_config from %r' % path)
-        return TestingConfig.frompath(path, config.parent, self,
-                                      mustExist = True,
-                                      config = config)
+        return lit.TestingConfig.TestingConfig.frompath(
+            path, config.parent, self, mustExist = True, config = config)
 
     def getBashPath(self):
         """getBashPath - Get the path to 'bash'"""
-        import os, Util
+        import os
 
         if self.bashPath is not None:
             return self.bashPath
 
-        self.bashPath = Util.which('bash', os.pathsep.join(self.path))
+        self.bashPath = lit.Util.which('bash', os.pathsep.join(self.path))
         if self.bashPath is None:
             # Check some known paths.
             for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'):
@@ -87,12 +93,11 @@ class LitConfig:
         return self.bashPath
 
     def getToolsPath(self, dir, paths, tools):
-        import os, Util
         if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
-            if not Util.checkToolsPath(dir, tools):
+            if not lit.Util.checkToolsPath(dir, tools):
                 return None
         else:
-            dir = Util.whichTools(tools, paths)
+            dir = lit.Util.whichTools(tools, paths)
 
         # bash
         self.bashPath = Util.which('bash', dir)

Modified: llvm/trunk/utils/lit/lit/ShUtil.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/ShUtil.py?rev=187860&r1=187859&r2=187860&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/ShUtil.py (original)
+++ llvm/trunk/utils/lit/lit/ShUtil.py Tue Aug  6 22:23:12 2013
@@ -1,7 +1,8 @@
+from __future__ import absolute_import
 import itertools
 
-import Util
-from ShCommands import Command, Pipeline, Seq
+import lit.Util
+from lit.ShCommands import Command, Pipeline, Seq
 
 class ShLexer:
     def __init__(self, data, win32Escapes = False):
@@ -74,8 +75,8 @@ class ShLexer:
                 # Outside of a string, '\\' escapes everything.
                 self.eat()
                 if self.pos == self.end:
-                    Util.warning("escape at end of quoted argument in: %r" % 
-                                 self.data)
+                    lit.Util.warning(
+                        "escape at end of quoted argument in: %r" % self.data)
                     return str
                 str += self.eat()
             else:
@@ -92,8 +93,8 @@ class ShLexer:
                 # Inside a '"' quoted string, '\\' only escapes the quote
                 # character and backslash, otherwise it is preserved.
                 if self.pos == self.end:
-                    Util.warning("escape at end of quoted argument in: %r" % 
-                                 self.data)
+                    lit.Util.warning(
+                        "escape at end of quoted argument in: %r" % self.data)
                     return str
                 c = self.eat()
                 if c == '"': # 
@@ -104,7 +105,7 @@ class ShLexer:
                     str += '\\' + c
             else:
                 str += c
-        Util.warning("missing quote character in %r" % self.data)
+        lit.Util.warning("missing quote character in %r" % self.data)
         return str
     
     def lex_arg_checked(self, c):

Modified: llvm/trunk/utils/lit/lit/TestFormats.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestFormats.py?rev=187860&r1=187859&r2=187860&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestFormats.py (original)
+++ llvm/trunk/utils/lit/lit/TestFormats.py Tue Aug  6 22:23:12 2013
@@ -1,9 +1,10 @@
+from __future__ import absolute_import
 import os
 import sys
 
-import Test
-import TestRunner
-import Util
+import lit.Test
+import lit.TestRunner
+import lit.Util
 
 kIsWindows = sys.platform in ['win32', 'cygwin']
 
@@ -27,8 +28,8 @@ class GoogleTest(object):
           localConfig: TestingConfig instance"""
 
         try:
-            lines = Util.capture([path, '--gtest_list_tests'],
-                                 env=localConfig.environment)
+            lines = lit.Util.capture([path, '--gtest_list_tests'],
+                                     env=localConfig.environment)
             if kIsWindows:
               lines = lines.replace('\r', '')
             lines = lines.split('\n')
@@ -63,7 +64,7 @@ class GoogleTest(object):
         # Discover the tests in this executable.
         for testname in self.getGTestTests(execpath, litConfig, localConfig):
             testPath = path_in_suite + (basename, testname)
-            yield Test.Test(testSuite, testPath, localConfig)
+            yield lit.Test.Test(testSuite, testPath, localConfig)
 
     def getTestsInDirectory(self, testSuite, path_in_suite,
                             litConfig, localConfig):
@@ -99,13 +100,13 @@ class GoogleTest(object):
         if litConfig.useValgrind:
             cmd = litConfig.valgrindArgs + cmd
 
-        out, err, exitCode = TestRunner.executeCommand(
+        out, err, exitCode = lit.TestRunner.executeCommand(
             cmd, env=test.config.environment)
 
         if not exitCode:
-            return Test.PASS,''
+            return lit.Test.PASS,''
 
-        return Test.FAIL, out + err
+        return lit.Test.FAIL, out + err
 
 ###
 
@@ -123,16 +124,16 @@ class FileBasedTest(object):
             if not os.path.isdir(filepath):
                 base,ext = os.path.splitext(filename)
                 if ext in localConfig.suffixes:
-                    yield Test.Test(testSuite, path_in_suite + (filename,),
-                                    localConfig)
+                    yield lit.Test.Test(testSuite, path_in_suite + (filename,),
+                                        localConfig)
 
 class ShTest(FileBasedTest):
     def __init__(self, execute_external = False):
         self.execute_external = execute_external
 
     def execute(self, test, litConfig):
-        return TestRunner.executeShTest(test, litConfig,
-                                        self.execute_external)
+        return lit.TestRunner.executeShTest(test, litConfig,
+                                            self.execute_external)
 
 ###
 
@@ -180,9 +181,9 @@ class OneCommandPerFileTest:
                 suffix = path[len(dir):]
                 if suffix.startswith(os.sep):
                     suffix = suffix[1:]
-                test = Test.Test(testSuite,
-                                 path_in_suite + tuple(suffix.split(os.sep)),
-                                 localConfig)
+                test = lit.Test.Test(
+                    testSuite, path_in_suite + tuple(suffix.split(os.sep)),
+                    localConfig)
                 # FIXME: Hack?
                 test.source_path = path
                 yield test
@@ -192,7 +193,7 @@ class OneCommandPerFileTest:
 
     def execute(self, test, litConfig):
         if test.config.unsupported:
-            return (Test.UNSUPPORTED, 'Test is unsupported')
+            return (lit.Test.UNSUPPORTED, 'Test is unsupported')
 
         cmd = list(self.command)
 
@@ -208,11 +209,11 @@ class OneCommandPerFileTest:
         else:
             cmd.append(test.getSourcePath())
 
-        out, err, exitCode = TestRunner.executeCommand(cmd)
+        out, err, exitCode = lit.TestRunner.executeCommand(cmd)
 
         diags = out + err
         if not exitCode and not diags.strip():
-            return Test.PASS,''
+            return lit.Test.PASS,''
 
         # Try to include some useful information.
         report = """Command: %s\n""" % ' '.join(["'%s'" % a
@@ -222,4 +223,4 @@ class OneCommandPerFileTest:
             report += "--\n%s--\n""" % open(tmp.name).read()
         report += """Output:\n--\n%s--""" % diags
 
-        return Test.FAIL, report
+        return lit.Test.FAIL, report

Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=187860&r1=187859&r2=187860&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Tue Aug  6 22:23:12 2013
@@ -1,14 +1,14 @@
+from __future__ import absolute_import
 import os, signal, subprocess, sys
 import StringIO
 
-import ShUtil
-import Test
-import Util
-
 import platform
 import tempfile
 
 import re
+import lit.ShUtil as ShUtil
+import lit.Test as Test
+import lit.Util as Util
 
 class InternalShellError(Exception):
     def __init__(self, command, message):

Modified: llvm/trunk/utils/lit/lit/__init__.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/__init__.py?rev=187860&r1=187859&r2=187860&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/__init__.py (original)
+++ llvm/trunk/utils/lit/lit/__init__.py Tue Aug  6 22:23:12 2013
@@ -1,6 +1,7 @@
 """'lit' Testing Tool"""
 
-from main import main
+from __future__ import absolute_import
+from .main import main
 
 __author__ = 'Daniel Dunbar'
 __email__ = 'daniel at zuster.org'

Modified: llvm/trunk/utils/lit/lit/main.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/main.py?rev=187860&r1=187859&r2=187860&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/main.py (original)
+++ llvm/trunk/utils/lit/lit/main.py Tue Aug  6 22:23:12 2013
@@ -6,14 +6,13 @@ lit - LLVM Integrated Tester.
 See lit.pod for more information.
 """
 
+from __future__ import absolute_import
 import math, os, platform, random, re, sys, time, threading, traceback
 
-import ProgressBar
-import TestRunner
-import Util
-
-import LitConfig
-import Test
+import lit.ProgressBar
+import lit.LitConfig
+import lit.Test
+import lit.Util
 
 import lit.discovery
 
@@ -129,7 +128,7 @@ class Tester(threading.Thread):
         except:
             if self.litConfig.debug:
                 raise
-            result = Test.UNRESOLVED
+            result = lit.Test.UNRESOLVED
             output = 'Exception during script execution:\n'
             output += traceback.format_exc()
             output += '\n'
@@ -257,7 +256,7 @@ def main(builtinParameters = {}):
 # I haven't seen this bug occur with 2.5.2 and later, so only enable multiple
 # threads by default there.
        if sys.hexversion >= 0x2050200:
-               opts.numThreads = Util.detectCPUs()
+               opts.numThreads = lit.Util.detectCPUs()
        else:
                opts.numThreads = 1
 
@@ -273,16 +272,17 @@ def main(builtinParameters = {}):
         userParams[name] = val
 
     # Create the global config object.
-    litConfig = LitConfig.LitConfig(progname = os.path.basename(sys.argv[0]),
-                                    path = opts.path,
-                                    quiet = opts.quiet,
-                                    useValgrind = opts.useValgrind,
-                                    valgrindLeakCheck = opts.valgrindLeakCheck,
-                                    valgrindArgs = opts.valgrindArgs,
-                                    debug = opts.debug,
-                                    isWindows = (platform.system()=='Windows'),
-                                    params = userParams,
-                                    config_prefix = opts.configPrefix)
+    litConfig = lit.LitConfig.LitConfig(
+        progname = os.path.basename(sys.argv[0]),
+        path = opts.path,
+        quiet = opts.quiet,
+        useValgrind = opts.useValgrind,
+        valgrindLeakCheck = opts.valgrindLeakCheck,
+        valgrindArgs = opts.valgrindArgs,
+        debug = opts.debug,
+        isWindows = (platform.system()=='Windows'),
+        params = userParams,
+        config_prefix = opts.configPrefix)
 
     tests = lit.discovery.find_tests_for_inputs(litConfig, inputs)
 
@@ -353,11 +353,11 @@ def main(builtinParameters = {}):
     if not opts.quiet:
         if opts.succinct and opts.useProgressBar:
             try:
-                tc = ProgressBar.TerminalController()
-                progressBar = ProgressBar.ProgressBar(tc, header)
+                tc = lit.ProgressBar.TerminalController()
+                progressBar = lit.ProgressBar.ProgressBar(tc, header)
             except ValueError:
                 print(header)
-                progressBar = ProgressBar.SimpleProgressBar('Testing: ')
+                progressBar = lit.ProgressBar.SimpleProgressBar('Testing: ')
         else:
             print(header)
 
@@ -384,7 +384,7 @@ def main(builtinParameters = {}):
     # Update results for any tests which weren't run.
     for t in tests:
         if t.result is None:
-            t.setResult(Test.UNRESOLVED, '', 0.0)
+            t.setResult(lit.Test.UNRESOLVED, '', 0.0)
 
     # List test results organized by kind.
     hasFailures = False
@@ -397,8 +397,8 @@ def main(builtinParameters = {}):
             hasFailures = True
 
     # FIXME: Show unresolved and (optionally) unsupported tests.
-    for title,code in (('Unexpected Passing Tests', Test.XPASS),
-                       ('Failing Tests', Test.FAIL)):
+    for title,code in (('Unexpected Passing Tests', lit.Test.XPASS),
+                       ('Failing Tests', lit.Test.FAIL)):
         elts = byCode.get(code)
         if not elts:
             continue
@@ -418,14 +418,14 @@ def main(builtinParameters = {}):
         byTime = list(times.items())
         byTime.sort(key = lambda item: item[1])
         if byTime:
-            Util.printHistogram(byTime, title='Tests')
+            lit.Util.printHistogram(byTime, title='Tests')
 
-    for name,code in (('Expected Passes    ', Test.PASS),
-                      ('Expected Failures  ', Test.XFAIL),
-                      ('Unsupported Tests  ', Test.UNSUPPORTED),
-                      ('Unresolved Tests   ', Test.UNRESOLVED),
-                      ('Unexpected Passes  ', Test.XPASS),
-                      ('Unexpected Failures', Test.FAIL),):
+    for name,code in (('Expected Passes    ', lit.Test.PASS),
+                      ('Expected Failures  ', lit.Test.XFAIL),
+                      ('Unsupported Tests  ', lit.Test.UNSUPPORTED),
+                      ('Unresolved Tests   ', lit.Test.UNRESOLVED),
+                      ('Unexpected Passes  ', lit.Test.XPASS),
+                      ('Unexpected Failures', lit.Test.FAIL),):
         if opts.quiet and not code.isFailure:
             continue
         N = len(byCode.get(code,[]))





More information about the llvm-commits mailing list