[Piglit] [PATCH 1/6] framework tests: Add helper for initializing classes
Dylan Baker
baker.dylan.c at gmail.com
Tue Sep 30 11:31:34 PDT 2014
Currently every single module implements a small helper for this
purpose. After this patch there is a single implementation in the utils
module.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/tests/core_tests.py | 13 ++-----------
framework/tests/dmesg_tests.py | 14 ++++++--------
framework/tests/exectest_test.py | 3 ++-
framework/tests/gleantest_tests.py | 5 +++--
framework/tests/glsl_parser_test_tests.py | 4 +++-
framework/tests/gtest_tests.py | 4 ++--
framework/tests/integration_tests.py | 11 ++++++-----
framework/tests/log_tests.py | 10 ++++------
framework/tests/opencv_tests.py | 4 ++--
framework/tests/profile_tests.py | 3 ++-
framework/tests/results_tests.py | 26 ++++----------------------
framework/tests/shader_test_tests.py | 3 ++-
framework/tests/status_tests.py | 8 +++-----
framework/tests/summary_tests.py | 3 +--
framework/tests/utils.py | 8 ++++++++
15 files changed, 50 insertions(+), 69 deletions(-)
diff --git a/framework/tests/core_tests.py b/framework/tests/core_tests.py
index 7ed3eb1..eb4d8fe 100644
--- a/framework/tests/core_tests.py
+++ b/framework/tests/core_tests.py
@@ -36,14 +36,6 @@ def _reset_piglit_config():
core.PIGLIT_CONFIG = ConfigParser.SafeConfigParser()
-def check_initialize(target):
- """ Check that a class initializes without error """
- func = target()
- # Asserting that func exists will fail for Group and TestrunResult which
- # are dict subclasses
- assert isinstance(func, target)
-
-
@utils.nose_generator
def test_generate_initialize():
""" Generator that creates tests to initialize all of the classes in core
@@ -54,12 +46,11 @@ def test_generate_initialize():
even work?
"""
- yieldable = check_initialize
for target in [core.Options]:
- yieldable.description = "Test that {} initializes".format(
+ utils.initialize.description = "Test that {} initializes".format(
target.__name__)
- yield yieldable, target
+ yield utils.initialize, target
def test_parse_listfile_return():
diff --git a/framework/tests/dmesg_tests.py b/framework/tests/dmesg_tests.py
index 108b76e..4bd1bcf 100644
--- a/framework/tests/dmesg_tests.py
+++ b/framework/tests/dmesg_tests.py
@@ -100,14 +100,12 @@ class TestDmesg(dmesg.BaseDmesg):
# Tests
-def test_linux_initialization():
- """ Test that LinuxDmesg initializes """
- dmesg.LinuxDmesg()
-
-
-def test_dummy_initialization():
- """ Test that DummyDmesg initializes """
- dmesg.DummyDmesg()
+ at utils.nose_generator
+def test_initialize():
+ """ Generate tests for intialization """
+ for x in [dmesg.LinuxDmesg, dmesg.DummyDmesg]:
+ utils.initialize.description = 'dmesg.{} initializes'.format(x)
+ yield utils.initialize, x
def test_get_dmesg_dummy():
diff --git a/framework/tests/exectest_test.py b/framework/tests/exectest_test.py
index 3610093..113f9ae 100644
--- a/framework/tests/exectest_test.py
+++ b/framework/tests/exectest_test.py
@@ -21,6 +21,7 @@
""" Tests for the exectest module """
import nose.tools as nt
+import framework.tests.utils as utils
from framework.exectest import PiglitTest, Test
@@ -41,7 +42,7 @@ class TestTest(Test):
# Tests
def test_initialize_piglittest():
""" Test that PiglitTest initializes correctly """
- PiglitTest('/bin/true')
+ utils.initialize(PiglitTest, 'true')
def test_run_return_early():
diff --git a/framework/tests/gleantest_tests.py b/framework/tests/gleantest_tests.py
index dd309d9..772dfd7 100644
--- a/framework/tests/gleantest_tests.py
+++ b/framework/tests/gleantest_tests.py
@@ -23,13 +23,14 @@
from __future__ import print_function
import os
from nose.plugins.skip import SkipTest
+
+import framework.tests.utils as utils
from framework.gleantest import GleanTest
def test_initialize_gleantest():
""" Test that GleanTest initilizes """
- test = GleanTest('name')
- assert test
+ utils.initialize(GleanTest, 'name')
def test_GLOBAL_PARAMS_assignment():
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index 5d3f61e..cfaeaa3 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -165,7 +165,9 @@ def test_empty_in_config():
def test_glslparser_initializer():
""" GLSLParserTest initializes """
- glsl.GLSLParserTest('tests/spec/glsl-es-1.00/compiler/version-macro.frag')
+ utils.initialize(
+ glsl.GLSLParserTest,
+ 'tests/spec/glsl-es-1.00/compiler/version-macro.frag')
def check_config_to_command(config, result):
diff --git a/framework/tests/gtest_tests.py b/framework/tests/gtest_tests.py
index 4f7a3f6..5fa4389 100644
--- a/framework/tests/gtest_tests.py
+++ b/framework/tests/gtest_tests.py
@@ -21,10 +21,10 @@
""" Module providing tests for gtest """
+import framework.tests.utils as utils
from framework.gtest import GTest
def test_initialize_gtest():
""" Test that GTest successfully initializes correctly """
- test = GTest('/bin/true')
- assert test
+ utils.initialize(GTest, 'true')
diff --git a/framework/tests/integration_tests.py b/framework/tests/integration_tests.py
index c304146..ca154c0 100644
--- a/framework/tests/integration_tests.py
+++ b/framework/tests/integration_tests.py
@@ -30,6 +30,7 @@ import importlib
import ConfigParser
from nose.plugins.skip import SkipTest
import framework.core
+import framework.tests.utils as utils
framework.core.get_config()
@@ -51,13 +52,13 @@ def test_xts_import():
def test_xts_xtstest():
""" xts.XTSTest initializes """
mod = _import('tests.xts')
- mod.XTSTest('name', 'testname', 'testnum')
+ utils.initialize(mod.XTSTest, 'name', 'testname', 'testnum')
def test_xts_xtsprofile():
""" xts.XTSProfile initializes """
mod = _import('tests.xts')
- mod.XTSProfile()
+ utils.initialize(mod.XTSProfile)
def test_igt_import():
@@ -68,7 +69,7 @@ def test_igt_import():
def test_igt_igttest():
""" igt.IGTTest initializes """
mod = _import('tests.igt')
- mod.IGTTest('foo')
+ utils.initialize(mod.IGTTest, 'foo')
def test_es3conform_import():
@@ -79,7 +80,7 @@ def test_es3conform_import():
def test_es3conform_gtftest():
""" es3conform.GTFTest initializes """
mod = _import('tests.es3conform')
- mod.GTFTest('testpath')
+ utils.initialize(mod.GTFTest, 'testpath')
def test_oglconform_import():
@@ -90,4 +91,4 @@ def test_oglconform_import():
def test_oglconform_oglctest():
""" oglconform.OGLCTest initializes """
mod = _import('tests.oglconform')
- mod.OGLCTest('catagory', 'subtest')
+ utils.initialize(mod.OGLCTest, 'catagory', 'subtest')
diff --git a/framework/tests/log_tests.py b/framework/tests/log_tests.py
index 794fcb5..85f5ce5 100644
--- a/framework/tests/log_tests.py
+++ b/framework/tests/log_tests.py
@@ -34,15 +34,13 @@ TEST_STATE = {'total': 0, 'complete': 0, 'lastlength': 0, 'running': [],
@utils.nose_generator
def test_initialize():
""" Generate tests for class initializiation """
- check_initialize = lambda c, *a: c(*a)
-
for name, class_ in [('QuiteLog', log.QuietLog),
('VerboseLog', log.VerboseLog)]:
- check_initialize.description = "{} initializes".format(name)
- yield check_initialize, class_, TEST_STATE
+ utils.initialize.description = "{} initializes".format(name)
+ yield utils.initialize, class_, TEST_STATE
- check_initialize.description = "LogManager initializes"
- yield check_initialize, log.LogManager, 'quiet', 100
+ utils.initialize.description = "LogManager initializes"
+ yield utils.initialize, log.LogManager, 'quiet', 100
def test_log_factory_returns_log():
diff --git a/framework/tests/opencv_tests.py b/framework/tests/opencv_tests.py
index 4658a9e..a095fdc 100644
--- a/framework/tests/opencv_tests.py
+++ b/framework/tests/opencv_tests.py
@@ -20,10 +20,10 @@
""" Module for testing opencv """
+import framework.tests.utils as utils
from framework.opencv import OpenCVTest
def test_initialize_opencvtest():
""" Test that opencvtest initializes correctly """
- test = OpenCVTest('test_prog', 'testname')
- assert test
+ utils.initialize(OpenCVTest, 'test_prog', 'testname')
diff --git a/framework/tests/profile_tests.py b/framework/tests/profile_tests.py
index c861cfc..5afc928 100644
--- a/framework/tests/profile_tests.py
+++ b/framework/tests/profile_tests.py
@@ -24,6 +24,7 @@ import copy
import platform
import nose.tools as nt
from nose.plugins.skip import SkipTest
+import framework.tests.utils as utils
import framework.core as core
import framework.dmesg as dmesg
import framework.profile as profile
@@ -31,7 +32,7 @@ import framework.profile as profile
def test_initialize_testprofile():
""" TestProfile initializes """
- profile.TestProfile()
+ utils.initialize(profile.TestProfile)
@nt.raises(SystemExit)
diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py
index 9c2ee32..f9c1ce2 100644
--- a/framework/tests/results_tests.py
+++ b/framework/tests/results_tests.py
@@ -43,14 +43,6 @@ BACKEND_INITIAL_META = {
JUNIT_SCHEMA = 'framework/tests/schema/junit-7.xsd'
-def check_initialize(target):
- """ Check that a class initializes without error """
- func = target()
- # Asserting that func exists will fail for Group and TestrunResult which
- # are dict subclasses
- assert isinstance(func, target)
-
-
@utils.nose_generator
def test_generate_initialize():
""" Generator that creates tests to initialize all of the classes in core
@@ -61,24 +53,14 @@ def test_generate_initialize():
even work?
"""
- yieldable = check_initialize
-
for target in [results.TestrunResult, results.TestResult]:
- yieldable.description = "Test that {} initializes".format(
+ utils.initialize.description = "Test that {} initializes".format(
target.__name__)
- yield yieldable, target
-
+ yield utils.initialize, target
-def test_initialize_jsonbackend():
- """ Test that JSONBackend initializes
-
- This needs to be handled separately from the others because it requires
- arguments
-
- """
with utils.tempdir() as tdir:
- func = results.JSONBackend(tdir, BACKEND_INITIAL_META)
- assert isinstance(func, results.JSONBackend)
+ utils.initialize.description = 'results.JSONBackend initializes'
+ yield utils.initialize, results.JSONBackend, tdir, BACKEND_INITIAL_META
def test_load_results_folder_as_main():
diff --git a/framework/tests/shader_test_tests.py b/framework/tests/shader_test_tests.py
index 6600dee..de57702 100644
--- a/framework/tests/shader_test_tests.py
+++ b/framework/tests/shader_test_tests.py
@@ -28,7 +28,8 @@ import framework.tests.utils as utils
def test_initialize_shader_test():
""" Test that ShaderTest initializes """
- shader_test.ShaderTest('tests/spec/glsl-es-1.00/execution/sanity.shader_test')
+ utils.initialize(shader_test.ShaderTest,
+ 'tests/spec/glsl-es-1.00/execution/sanity.shader_test')
def test_parse_gl_test_no_decimal():
diff --git a/framework/tests/status_tests.py b/framework/tests/status_tests.py
index 34cbc9c..63f7ab9 100644
--- a/framework/tests/status_tests.py
+++ b/framework/tests/status_tests.py
@@ -51,14 +51,12 @@ NO_OPS = ('skip', 'notrun')
def initialize_status():
""" status.Status inializes """
- test = status.Status('test', 1)
- assert test
+ utils.initialize(status.Status, 'test', 1)
def initialize_nochangestatus():
- """ NoChangeStatus initializes """
- nc = status.NoChangeStatus('test')
- assert nc
+ """ status.NoChangeStatus initializes """
+ utils.initialize(status.NoChangeStatus, 'test')
def compare_status_nochangestatus():
diff --git a/framework/tests/summary_tests.py b/framework/tests/summary_tests.py
index 61cfbfe..2f34e55 100644
--- a/framework/tests/summary_tests.py
+++ b/framework/tests/summary_tests.py
@@ -32,8 +32,7 @@ import framework.tests.utils as utils
def test_initialize_summary():
""" Test that Summary initializes """
with utils.resultfile() as tfile:
- test = summary.Summary([tfile.name])
- assert test
+ utils.initialize(summary.Summary, [tfile.name])
@utils.nose_generator
diff --git a/framework/tests/utils.py b/framework/tests/utils.py
index 2694fab..9ea44e3 100644
--- a/framework/tests/utils.py
+++ b/framework/tests/utils.py
@@ -252,3 +252,11 @@ class StaticDirectory(object):
def teardown_class(cls):
""" Remove the temporary directory """
shutil.rmtree(cls.tdir)
+
+
+def initialize(class_, *args, **kwargs):
+ """ Test that a class will initialize with the given arguments """
+ try:
+ class_(*args, **kwargs)
+ except Exception as e:
+ raise AssertionError(e)
--
2.1.1
More information about the Piglit
mailing list