[Piglit] [PATCH 05/13] core_tests.py: Add some basic initialization tests for core

Dylan Baker baker.dylan.c at gmail.com
Thu Mar 6 14:47:15 PST 2014


These tests help to reduce obvious breakages in the core module by
making sure that there are no interpreter related bugs. In a language
like C one wouldn't need these kinds of tests because the compiler would
catch them.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/tests/core_tests.py | 64 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 framework/tests/core_tests.py

diff --git a/framework/tests/core_tests.py b/framework/tests/core_tests.py
new file mode 100644
index 0000000..39bb1b3
--- /dev/null
+++ b/framework/tests/core_tests.py
@@ -0,0 +1,64 @@
+# Copyright (c) 2014 Intel Corporation
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+""" Module providing tests for the core module """
+
+
+import tempfile
+import framework.core as core
+
+
+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)
+
+
+def test_generate_initialize():
+    """ Generator that creates tests to initialize all of the classes in core
+
+    In a compiled language the compiler provides this kind of checking, but in
+    an interpreted language like python you don't have a compiler test. The
+    unit tests generated by this function serve as a similar test, does this
+    even work?
+
+    """
+    yieldable = check_initialize
+
+    for target in [core.TestProfile, core.Group, core.Test, core.Environment,
+                   core.TestrunResult, core.TestResult,
+                   core.PiglitJSONEncoder]:
+        yieldable.description = "Test that {} initializes".format(
+            target.__name__)
+        yield yieldable, target
+
+
+def test_initialize_jsonwriter():
+    """ Test that JSONWriter initializes
+
+    This needs to be handled separately from the others because it requires
+    arguments
+
+    """
+    with tempfile.TemporaryFile() as tfile:
+        func = core.JSONWriter(tfile)
+        assert isinstance(func, core.JSONWriter)
-- 
1.9.0



More information about the Piglit mailing list