[LNT] r307802 - Fix `lnt showtests`; Rework lnt.tests.__init__

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 12 09:14:55 PDT 2017


Author: matze
Date: Wed Jul 12 09:14:55 2017
New Revision: 307802

URL: http://llvm.org/viewvc/llvm-project?rev=307802&view=rev
Log:
Fix `lnt showtests`; Rework lnt.tests.__init__

- The command broke in r306534. Add a unittest so this doesn't happen
  again.
- Rewrite lnt.tests.__init__ and simplify it; Use module docstring
  instead of TestClass.describe() for the descriptions. This looks more
  pythonic and avoids unnecessarily creating objects just show the
  description.

Added:
    lnt/trunk/tests/lnttool/showtests.shtest
Modified:
    lnt/trunk/lnt/lnttool/main.py
    lnt/trunk/lnt/tests/__init__.py
    lnt/trunk/lnt/tests/compile.py
    lnt/trunk/lnt/tests/nt.py
    lnt/trunk/lnt/tests/test_suite.py

Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=307802&r1=307801&r2=307802&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Wed Jul 12 09:14:55 2017
@@ -132,15 +132,16 @@ action_runtest.add_command(TestSuiteTest
 @click.command("showtests")
 def action_showtests():
     """show the available built-in tests"""
-
     import lnt.tests
+    import inspect
 
     print 'Available tests:'
-    test_names = lnt.tests.get_test_names()
+    test_names = lnt.tests.get_names()
     max_name = max(map(len, test_names))
     for name in test_names:
-        print '  %-*s - %s' % (max_name, name,
-                               lnt.tests.get_test_description(name))
+        test_module = lnt.tests.get_module(name)
+        description = inspect.cleandoc(test_module.__doc__)
+        print '  %-*s - %s' % (max_name, name, description)
 
 
 @click.command("submit")

Modified: lnt/trunk/lnt/tests/__init__.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/__init__.py?rev=307802&r1=307801&r2=307802&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/__init__.py (original)
+++ lnt/trunk/lnt/tests/__init__.py Wed Jul 12 09:14:55 2017
@@ -1,42 +1,36 @@
 """
 Access to built-in tests.
 """
-
 # FIXME: There are better ways to do this, no doubt. We also would like this to
 # be extensible outside of the installation. Lookup how 'nose' handles this.
 
-known_tests = set(['compile', 'nt', 'test_suite'])
+_known_tests = set(['compile', 'nt', 'test_suite'])
+
 
-def get_test_names():
+def get_names():
     """get_test_names() -> list
 
     Return the list of known built-in test names.
     """
+    return _known_tests
 
-    return known_tests
 
-def get_test_instance(name):
+def get_module(name):
+    import importlib
     """get_test_instance(name) -> lnt.test.BuiltinTest
 
     Return an instance of the named test.
     """
-    # Allow hyphens instead of underscores when specifying the test on the command
-    # line. (test-suite instead of test_suite).
+    # Allow hyphens instead of underscores when specifying the test on the
+    # command line. (test-suite instead of test_suite).
     name = name.replace('-', '_')
 
-    if name not in known_tests:
-        raise KeyError, name
-
-    module = getattr(__import__('lnt.tests.%s' % name, level=0).tests,
-                     name)
-    return module.create_instance()
+    if name not in _known_tests:
+        raise KeyError(name)
 
-def get_test_description(name):
-    """get_test_description(name) -> str
-
-    Return the description of the given test.
-    """
+    module_name = "lnt.tests.%s" % name
+    module = importlib.import_module(module_name)
+    return module
 
-    return get_test_instance(name).describe()
 
-__all__ = ['get_test_names', 'get_test_instance', 'get_test_description']
+__all__ = ['get_names', 'get_module']

Modified: lnt/trunk/lnt/tests/compile.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/compile.py?rev=307802&r1=307801&r2=307802&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/compile.py (original)
+++ lnt/trunk/lnt/tests/compile.py Wed Jul 12 09:14:55 2017
@@ -1,3 +1,4 @@
+"""Single file compile-time performance testing"""
 import errno
 import hashlib
 import json
@@ -702,9 +703,6 @@ We run each of the compile time tests in
 
 
 class CompileTest(builtintest.BuiltinTest):
-    def describe(self):
-        return 'Single file compile-time performance testing'
-
     # FIXME: an equivalent to argparse's add_argument_group is not implemented
     #        on click. Need to review it when such functionality is available.
     #        https://github.com/pallets/click/issues/373

Modified: lnt/trunk/lnt/tests/nt.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/nt.py?rev=307802&r1=307801&r2=307802&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/nt.py (original)
+++ lnt/trunk/lnt/tests/nt.py Wed Jul 12 09:14:55 2017
@@ -1,3 +1,4 @@
+"""LLVM test-suite compile and execution tests"""
 import csv
 import os
 import platform
@@ -1496,9 +1497,6 @@ nightly test, but it should not be used
 
 
 class NTTest(builtintest.BuiltinTest):
-    def describe(self):
-        return 'LLVM test-suite compile and execution tests'
-
     # FIXME: an equivalent to argparse's add_argument_group is not implemented
     #        on click. Need to review it when such functionality is available.
     #        https://github.com/pallets/click/issues/373

Modified: lnt/trunk/lnt/tests/test_suite.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/test_suite.py?rev=307802&r1=307801&r2=307802&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/test_suite.py (original)
+++ lnt/trunk/lnt/tests/test_suite.py Wed Jul 12 09:14:55 2017
@@ -1,3 +1,4 @@
+"""LLVM test-suite"""
 import subprocess
 import tempfile
 import json
@@ -174,9 +175,6 @@ class TestSuiteTest(BuiltinTest):
         self.compiled = False
         self.trained = False
 
-    def describe(self):
-        return "LLVM test-suite"
-
     @staticmethod
     @click.command("test-suite")
     @click.argument("label", default=platform.uname()[1], required=False,

Added: lnt/trunk/tests/lnttool/showtests.shtest
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lnttool/showtests.shtest?rev=307802&view=auto
==============================================================================
--- lnt/trunk/tests/lnttool/showtests.shtest (added)
+++ lnt/trunk/tests/lnttool/showtests.shtest Wed Jul 12 09:14:55 2017
@@ -0,0 +1,5 @@
+# RUN: lnt showtests | FileCheck %s
+# CHECK: Available tests:
+# CHECK-NEXT: compile    - Single file compile-time performance testing
+# CHECK-NEXT: test_suite - LLVM test-suite
+# CHECK-NEXT: nt         - LLVM test-suite compile and execution tests




More information about the llvm-commits mailing list