[Piglit] [RFC 3/9] backends: don't * import into backends __init__

Dylan Baker baker.dylan.c at gmail.com
Mon Apr 6 14:30:13 PDT 2015


This was a design mistake from the start, it means that each module in
the backends package need to be aware of each other, and have unique
names, which defeats the entire value of namespaces.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/backends/__init__.py    |  9 +++------
 framework/results.py              |  4 ++--
 framework/tests/backends_tests.py | 20 ++++++++++----------
 framework/tests/dmesg_tests.py    |  2 +-
 framework/tests/results_tests.py  |  6 +++---
 5 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/framework/backends/__init__.py b/framework/backends/__init__.py
index 257bba9..eee088e 100644
--- a/framework/backends/__init__.py
+++ b/framework/backends/__init__.py
@@ -20,10 +20,7 @@
 
 """ Import public backend classes into one place """
 
-# pylint: disable=wildcard-import
-from .json import *
-from .junit import *
-
+from . import json, junit
 
 # A list of available backends
 BACKENDS = ['json', 'junit']
@@ -32,8 +29,8 @@ BACKENDS = ['json', 'junit']
 def get_backend(backend):
     """ Returns a BackendInstance based on the string passed """
     backends = {
-        'json': JSONBackend,
-        'junit': JUnitBackend,
+        'json': json.JSONBackend,
+        'junit': junit.JUnitBackend,
     }
 
     # Be sure that we're exporting the same list of backends that we actually
diff --git a/framework/results.py b/framework/results.py
index 7e5de48..1710228 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -32,8 +32,8 @@ except ImportError:
     import json
 
 import framework.status as status
-from framework.backends import (CURRENT_JSON_VERSION, piglit_encoder,
-                                JSONBackend)
+from framework.backends.json import (CURRENT_JSON_VERSION, piglit_encoder,
+                                     JSONBackend)
 
 __all__ = [
     'ResultsLoadError',
diff --git a/framework/tests/backends_tests.py b/framework/tests/backends_tests.py
index dbf80f9..7b94fef 100644
--- a/framework/tests/backends_tests.py
+++ b/framework/tests/backends_tests.py
@@ -70,8 +70,8 @@ def test_get_backend():
     # We use a hand generated list here to ensure that we are getting what we
     # expect
     backends_ = {
-        'json': backends.JSONBackend,
-        'junit': backends.JUnitBackend,
+        'json': backends.json.JSONBackend,
+        'junit': backends.junit.JUnitBackend,
     }
 
     def check(n, i):
@@ -86,7 +86,7 @@ class TestJunitNoTests(utils.StaticDirectory):
     @classmethod
     def setup_class(cls):
         super(TestJunitNoTests, cls).setup_class()
-        test = backends.JUnitBackend(cls.tdir)
+        test = backends.junit.JUnitBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.finalize()
         cls.test_file = os.path.join(cls.tdir, 'results.xml')
@@ -109,7 +109,7 @@ class TestJUnitSingleTest(TestJunitNoTests):
     def setup_class(cls):
         super(TestJUnitSingleTest, cls).setup_class()
         cls.test_file = os.path.join(cls.tdir, 'results.xml')
-        test = backends.JUnitBackend(cls.tdir)
+        test = backends.junit.JUnitBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(
             grouptools.join('a', 'test', 'group', 'test1'),
@@ -141,7 +141,7 @@ class TestJUnitMultiTest(TestJUnitSingleTest):
     def setup_class(cls):
         super(TestJUnitMultiTest, cls).setup_class()
         cls.test_file = os.path.join(cls.tdir, 'results.xml')
-        test = backends.JUnitBackend(cls.tdir)
+        test = backends.junit.JUnitBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(
             grouptools.join('a', 'test', 'group', 'test1'),
@@ -178,7 +178,7 @@ class TestJUnitMultiTest(TestJUnitSingleTest):
 def test_junit_replace():
     """JUnitBackend.write_test: '{seperator}' is replaced with '.'"""
     with utils.tempdir() as tdir:
-        test = backends.JUnitBackend(tdir)
+        test = backends.junit.JUnitBackend(tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(
             grouptools.join('a', 'test', 'group', 'test1'),
@@ -201,7 +201,7 @@ def test_junit_replace():
 def test_json_initialize_metadata():
     """ JSONBackend.initialize() produces a metadata.json file """
     with utils.tempdir() as f:
-        test = backends.JSONBackend(f)
+        test = backends.json.JSONBackend(f)
         test.initialize(BACKEND_INITIAL_META)
 
         nt.ok_(os.path.exists(os.path.join(f, 'metadata.json')))
@@ -218,7 +218,7 @@ class TestJSONTestMethod(utils.StaticDirectory):
             'err': 'this is stderr',
         })
         super(TestJSONTestMethod, cls).setup_class()
-        test = backends.JSONBackend(cls.tdir)
+        test = backends.json.JSONBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(cls.test_name, cls.result)
 
@@ -253,7 +253,7 @@ class TestJSONTestFinalize(utils.StaticDirectory):
             'err': 'this is stderr',
         })
         super(TestJSONTestFinalize, cls).setup_class()
-        test = backends.JSONBackend(cls.tdir)
+        test = backends.json.JSONBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(cls.test_name, cls.result)
         test.finalize()
@@ -282,7 +282,7 @@ class TestJSONTestFinalize(utils.StaticDirectory):
 def test_junit_skips_bad_tests():
     """ backends.JUnitBackend skips illformed tests """
     with utils.tempdir() as tdir:
-        test = backends.JUnitBackend(tdir)
+        test = backends.junit.JUnitBackend(tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(
             grouptools.join('a', 'test', 'group', 'test1'),
diff --git a/framework/tests/dmesg_tests.py b/framework/tests/dmesg_tests.py
index 9a7fef9..4773a49 100644
--- a/framework/tests/dmesg_tests.py
+++ b/framework/tests/dmesg_tests.py
@@ -325,7 +325,7 @@ def test_json_serialize_updated_result():
     test._new_messages = ['some', 'new', 'messages']
     result = test.update_result(result)
 
-    encoder = json.JSONEncoder(default=framework.backends.piglit_encoder)
+    encoder = json.JSONEncoder(default=framework.backends.json.piglit_encoder)
     encoder.encode(result)
 
 
diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py
index 8e1a894..00e64dc 100644
--- a/framework/tests/results_tests.py
+++ b/framework/tests/results_tests.py
@@ -162,7 +162,7 @@ def test_resume_non_folder():
 def test_resume_load():
     """ TestrunResult.resume loads with good results """
     with utils.tempdir() as f:
-        backend = backends.JSONBackend(f)
+        backend = backends.json.JSONBackend(f)
         backend.initialize(BACKEND_INITIAL_META)
         backend.write_test(grouptools.join("group1', 'test1"), {'result': 'fail'})
         backend.write_test(grouptools.join("group1', 'test2"), {'result': 'pass'})
@@ -177,7 +177,7 @@ def test_resume_load():
 def test_resume_load_valid():
     """ TestrunResult.resume loads valid results """
     with utils.tempdir() as f:
-        backend = backends.JSONBackend(f)
+        backend = backends.json.JSONBackend(f)
         backend.initialize(BACKEND_INITIAL_META)
         backend.write_test(grouptools.join('group1', 'test1'), {'result': 'fail'})
         backend.write_test(grouptools.join('group1', 'test2'), {'result': 'pass'})
@@ -196,7 +196,7 @@ def test_resume_load_valid():
 def test_resume_load_invalid():
     """ TestrunResult.resume ignores invalid results """
     with utils.tempdir() as f:
-        backend = backends.JSONBackend(f)
+        backend = backends.json.JSONBackend(f)
         backend.initialize(BACKEND_INITIAL_META)
         backend.write_test(grouptools.join('group1', 'test1'), {'result': 'fail'})
         backend.write_test(grouptools.join('group1', 'test2'), {'result': 'pass'})
-- 
2.3.5



More information about the Piglit mailing list