[Piglit] [PATCH 07/49] unittests: Port generator tests to pytest.
Dylan Baker
dylan at pnwbakers.com
Fri Jul 29 18:38:53 UTC 2016
This port uses a lot less code, is much simpler, and is able to mark
tests as slow or very_slow (which is unfortunately necessary).
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
tox.ini | 24 +++---
unittests/generators/test_generators.py | 129 ++++++++++++++------------------
2 files changed, 73 insertions(+), 80 deletions(-)
diff --git a/tox.ini b/tox.ini
index d6a845f..24e48ed 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,24 +2,30 @@
envlist = py{27,33,34,35}-{generator,noaccel}, py{27,33,34,35}-accel-{win,nix}
skipsdist = True
+[pytest]
+python_paths = framework/ generated_tests/
+
[testenv]
passenv=HOME
setenv =
USERNAME = foo
deps =
- nose
- coverage
- wrapt
- six==1.5.2
- accel: simplejson
accel-nix: lxml
+ accel: simplejson
+ generator: numpy==1.7.0
+ generator: pytest
+ generator: pytest-pythonpath
+ generator: pytest-raises
+ generator: pytest-warnings
+ mock==1.0.1
py27-accel-nix,py{33,34,35}-{accel,noaccel}: psutil
- py27-{accel,noaccel}: mock==1.0.1
py27-accel-nix: backports.lzma
py27-accel-nix: subprocess32
- py{27,33,34}: mako==0.8.0
py35: mako==1.0.2
- generator: numpy==1.7.0
+ py{27,33,34}: mako==0.8.0
+ six==1.5.2
+ wrapt
+ {accel,noaccel}: nose
commands =
{accel,noaccel}: nosetests unittests -e generators []
- generator: nosetests unittests/generators []
+ generator: py.test -rw unittests/generators
diff --git a/unittests/generators/test_generators.py b/unittests/generators/test_generators.py
index 9ad0aaf..ce3ce5d 100644
--- a/unittests/generators/test_generators.py
+++ b/unittests/generators/test_generators.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2015-2016 Intel Corporation
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -24,74 +22,63 @@
This needs to be compatible with both python2 and python3.
+Tests that take more than ~10 seconds should be marked as "slow" and tests that
+take more than ~30 seconds should be marked as "very_slow".
"""
-from __future__ import absolute_import, division, print_function
-import os
-import subprocess
-
-import nose.tools as nt
-
-from .. import utils
-
-
-GENERATOR_DIR = os.path.abspath(
- os.path.join(os.path.dirname(__file__), '..', '..', 'generated_tests'))
-
-BLACKLIST = {
- # These will never need to be tested, they're modules.
- 'builtin_function.py',
- 'builtin_function_fp64.py',
- 'genclbuiltins.py',
-
- # these (or some subset) should run eventually.
- 'random_ubo.py',
- 'random_ubo_trim.py',
- 'random_ubo-arb_uniform_buffer_object.py',
-}
-
-BLACKLIST = set(os.path.join(GENERATOR_DIR, _p) for _p in BLACKLIST)
-
-
-def discover_generators():
- """Discover all of the generators and return that as a set.
-
- Removes all generators in the BLACKLIST constant.
-
- """
- def fqp(path):
- """make fully-qualified path."""
- return os.path.abspath(os.path.join(GENERATOR_DIR, path))
-
- contents = set(fqp(p) for p in os.listdir(GENERATOR_DIR)
- if p.endswith('.py'))
- contents.difference_update(BLACKLIST)
- return contents
-
-
- at utils.nose.generator
-def test_generators():
- """Generate tests for the various generators."""
-
- @utils.nose.test_in_tempdir
- def test(name):
- """Tester function."""
- msg = ''
-
- with open(os.devnull, 'w') as d:
- proc = subprocess.Popen(['python', name],
- stderr=subprocess.PIPE,
- stdout=d)
- _, err = proc.communicate()
-
- if proc.returncode != 0:
- err = err.decode('utf-8')
-
- raise utils.nose.TestFailure(
- "failed with message:\n {}".format(err))
-
- description = 'generator: {} runs successfully'
-
- for generator in discover_generators():
- test.description = description.format(os.path.basename(generator))
- yield test, generator
+from __future__ import (
+ absolute_import, division, print_function, unicode_literals
+)
+import importlib
+try:
+ import mock
+except ImportError:
+ from unittest import mock
+
+import pytest
+
+
+ at pytest.mark.parametrize('name', [
+ 'gen_builtin_packing_tests',
+ 'gen_builtin_uniform_tests_fp64',
+ 'gen_cl_common_builtins',
+ 'gen_cl_int_builtins',
+ 'gen_cl_math_builtins',
+ 'gen_cl_relational_builtins',
+ 'gen_cl_store_tests',
+ 'gen_const_builtin_equal_tests',
+ 'gen_constant_array_size_tests_fp64',
+ 'gen_conversion_fp64',
+ 'gen_extensions_defined',
+ 'gen_flat_interpolation_qualifier',
+ 'gen_inout_fp64',
+ 'gen_interpolation_tests',
+ 'gen_non-lvalue_tests',
+ 'gen_outerproduct_invalid_params',
+ 'gen_outerproduct_tests',
+ 'gen_shader_bit_encoding_tests',
+ 'gen_shader_image_load_store_tests',
+ 'gen_shader_precision_tests',
+ 'gen_tcs_input_tests',
+ 'gen_tes_input_tests',
+ 'gen_texture_lod_tests',
+ 'gen_texture_query_lod_tests',
+ 'gen_uniform_initializer_tests',
+ 'gen_variable_index_read_tests',
+ 'gen_variable_index_write_tests',
+ 'gen_vp_tex',
+ 'interpolation-qualifier-built-in-variable',
+ pytest.mark.slow('gen_builtin_uniform_tests'),
+ pytest.mark.slow('gen_constant_array_size_tests'),
+ pytest.mark.very_slow('gen_vs_in_fp64'),
+])
+def test_generators(name, tmpdir):
+ """Teat each generator."""
+ mod = importlib.import_module(name)
+ tmpdir.chdir()
+
+ # Some tests do checks for sys.argv, so mock that out. Also mock out
+ # print since we don't want a giant list of tests printed on an error.
+ with mock.patch('sys.argv', [name]), \
+ mock.patch.object(mod, 'print', mock.Mock(), create=True):
+ mod.main()
--
2.9.0
More information about the Piglit
mailing list