[Piglit] [PATCH 22/49] unittests: port profile tests to pytest
Dylan Baker
dylan at pnwbakers.com
Fri Jul 29 18:39:08 UTC 2016
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
unittests/framework/test_profile.py | 370 +++++++++++++++++++++++++++++++++++
unittests/framework/utils.py | 45 +++++
unittests/profile_tests.py | 376 ------------------------------------
3 files changed, 415 insertions(+), 376 deletions(-)
create mode 100644 unittests/framework/test_profile.py
create mode 100644 unittests/framework/utils.py
delete mode 100644 unittests/profile_tests.py
diff --git a/unittests/framework/test_profile.py b/unittests/framework/test_profile.py
new file mode 100644
index 0000000..4ff9ea5
--- /dev/null
+++ b/unittests/framework/test_profile.py
@@ -0,0 +1,370 @@
+# Copyright (c) 2014, 2016 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.
+
+""" Provides test for the framework.profile modules """
+
+from __future__ import (
+ absolute_import, division, print_function, unicode_literals
+)
+import copy
+try:
+ from unittest import mock
+except ImportError:
+ import mock
+
+import pytest
+import six
+
+from framework import dmesg
+from framework import exceptions
+from framework import grouptools
+from framework import options
+from framework import profile
+from framework.test.gleantest import GleanTest
+from . import utils
+from . import skip
+
+# pylint: disable=invalid-name,no-self-use,protected-access
+
+
+class TestLoadTestProfile(object):
+ """Tests for profile.load_test_profile."""
+
+ def test_no_profile_attribute(self, tmpdir):
+ """profile.load_test_profile: Loading a module with no profile name
+ exits.
+
+ Because load_test_profile uses test.{} to load a module we need a
+ module in tests that doesn't have a profile attribute. The only module
+ that currently meets that requirement is __init__.py
+ """
+ p = tmpdir.join('foo.profile')
+
+ with pytest.raises(exceptions.PiglitFatalError):
+ profile.load_test_profile(six.text_type(p))
+
+ def test_no_such_module(self, tmpdir):
+ """profile.load_test_profile: Trying to load a non-existent module
+ exits.
+ """
+ # Ensure that the module will not exist by moving to an empty temporary
+ # directory
+ tmpdir.chdir()
+ with pytest.raises(exceptions.PiglitFatalError):
+ profile.load_test_profile('this_module_will_never_ever_exist')
+
+ def test_return_type(self):
+ """profile.load_test_profile: returns a TestProfile instance."""
+ assert isinstance(profile.load_test_profile('sanity'),
+ profile.TestProfile)
+
+
+class TestTestProfile(object):
+ """Tests for profile.TestProfile."""
+
+ def test_default_dmesg(self):
+ """profile.TestProfile: Dmesg is dummy by default."""
+ profile_ = profile.TestProfile()
+ assert isinstance(profile_.dmesg, dmesg.DummyDmesg)
+
+ @skip.linux
+ def test_set_dmesg_true(self):
+ """profile.TestProfile: Dmesg returns an appropriate dmesg is set to
+ True.
+ """
+ profile_ = profile.TestProfile()
+ profile_.dmesg = True
+ assert isinstance(profile_.dmesg, dmesg.LinuxDmesg)
+
+ @skip.linux
+ def test_set_dmesg_false(self):
+ """profile.TestProfile: Dmesg returns a DummyDmesg if set to False."""
+ profile_ = profile.TestProfile()
+ profile_.dmesg = True
+ profile_.dmesg = False
+ assert isinstance(profile_.dmesg, dmesg.DummyDmesg)
+
+ def test_update_test_list(self):
+ """profile.TestProfile.update(): updates TestProfile.test_list"""
+ profile1 = profile.TestProfile()
+ group1 = grouptools.join('group1', 'test1')
+ group2 = grouptools.join('group1', 'test2')
+
+ profile1.test_list[group1] = utils.Test(['test1'])
+
+ profile2 = profile.TestProfile()
+ profile2.test_list[group1] = utils.Test(['test3'])
+ profile2.test_list[group2] = utils.Test(['test2'])
+
+ with profile1.allow_reassignment:
+ profile1.update(profile2)
+
+ assert dict(profile1.test_list) == dict(profile2.test_list)
+
+ class TestPrepareTestList(object):
+ """Create tests for TestProfile.prepare_test_list filtering."""
+
+ @classmethod
+ def setup_class(cls):
+ cls.opts = None
+ cls.data = None
+ cls.__patcher = mock.patch('framework.profile.options.OPTIONS',
+ new_callable=options._Options)
+
+ def setup(self):
+ """Setup each test."""
+ self.data = profile.TestDict()
+ self.data[grouptools.join('group1', 'test1')] = \
+ utils.Test(['thingy'])
+ self.data[grouptools.join('group1', 'group3', 'test2')] = \
+ utils.Test(['thing'])
+ self.data[grouptools.join('group3', 'test5')] = \
+ utils.Test(['other'])
+ self.data[grouptools.join('group4', 'Test9')] = \
+ utils.Test(['is_caps'])
+ self.opts = self.__patcher.start()
+
+ def teardown(self):
+ self.__patcher.stop()
+
+ def test_matches_filter_mar_1(self):
+ """profile.TestProfile.prepare_test_list: 'not env.filter or
+ matches_any_regex()' env.filter is False.
+
+ Nothing should be filtered.
+ """
+ profile_ = profile.TestProfile()
+ profile_.test_list = self.data
+ profile_._prepare_test_list()
+
+ assert dict(profile_.test_list) == dict(self.data)
+
+ def test_matches_filter_mar_2(self):
+ """profile.TestProfile.prepare_test_list: 'not env.filter or
+ matches_any_regex()' mar is False.
+ """
+ self.opts.include_filter = ['test5']
+
+ profile_ = profile.TestProfile()
+ profile_.test_list = self.data
+ profile_._prepare_test_list()
+
+ baseline = {
+ grouptools.join('group3', 'test5'): utils.Test(['other'])}
+
+ assert dict(profile_.test_list) == baseline
+
+ def test_matches_env_exclude(self):
+ """profile.TestProfile.prepare_test_list: 'not path in
+ env.exclude_tests'.
+ """
+ # Pylint can't figure out that self.opts isn't a dict, but an
+ # options._Option object.
+ self.opts.exclude_tests.add(grouptools.join('group3', 'test5')) # pylint: disable=no-member
+
+ baseline = copy.deepcopy(self.data)
+ del baseline[grouptools.join('group3', 'test5')]
+
+ profile_ = profile.TestProfile()
+ profile_.test_list = self.data
+ profile_._prepare_test_list()
+
+ assert dict(profile_.test_list) == dict(baseline)
+
+ def test_matches_exclude_mar(self):
+ """profile.TestProfile.prepare_test_list: 'not
+ matches_any_regexp()'.
+ """
+ self.opts.exclude_filter = ['test5']
+
+ baseline = copy.deepcopy(self.data)
+ del baseline[grouptools.join('group3', 'test5')]
+
+ profile_ = profile.TestProfile()
+ profile_.test_list = self.data
+ profile_._prepare_test_list()
+
+ assert dict(profile_.test_list) == dict(baseline)
+
+ def test_matches_include_caps(self):
+ """profile.TestProfile.prepare_test_list: matches capitalized
+ tests.
+ """
+ self.opts.exclude_filter = ['test9']
+
+ profile_ = profile.TestProfile()
+ profile_.test_list = self.data
+ profile_._prepare_test_list()
+
+ assert grouptools.join('group4', 'Test9') not in profile_.test_list
+
+ class TestGroupManager(object):
+ """Tests for TestProfile.group_manager."""
+
+ profile = None
+
+ def setup(self):
+ self.profile = profile.TestProfile()
+
+ def test_no_name_args_eq_one(self):
+ """no name and len(args) == 1 is valid."""
+ with self.profile.group_manager(utils.Test, 'foo') as g:
+ g(['a'])
+
+ assert grouptools.join('foo', 'a') in self.profile.test_list
+
+ def test_no_name_args_gt_one(self):
+ """no name and len(args) > 1 is valid."""
+ with self.profile.group_manager(utils.Test, 'foo') as g:
+ g(['a', 'b'])
+
+ assert grouptools.join('foo', 'a b') in self.profile.test_list
+
+ def test_name(self):
+ """name plus len(args) > 1 is valid."""
+ with self.profile.group_manager(utils.Test, 'foo') as g:
+ g(['a', 'b'], 'a')
+
+ assert grouptools.join('foo', 'a') in self.profile.test_list
+
+ def test_adder_kwargs_passed(self):
+ """Extra kwargs passed to the adder function are passed to the
+ Test.
+ """
+ with self.profile.group_manager(utils.Test, 'foo') as g:
+ g(['a'], run_concurrent=True)
+ test = self.profile.test_list[grouptools.join('foo', 'a')]
+
+ assert test.run_concurrent is True
+
+ def test_context_manager_keyword_args_passed(self):
+ """kwargs passed to the context_manager are passed to the Test."""
+ with self.profile.group_manager(
+ utils.Test, 'foo', run_concurrent=True) as g: # pylint: disable=bad-continuation
+ # This is a pylint bug, there's an upstream report
+ g(['a'])
+ test = self.profile.test_list[grouptools.join('foo', 'a')]
+
+ assert test.run_concurrent is True
+
+ def test_adder_kwargs_overwrite_context_manager_kwargs(self):
+ """default_args are overwritten by kwargs."""
+ with self.profile.group_manager(
+ utils.Test, 'foo', run_concurrent=True) as g: # pylint: disable=bad-continuation
+ # This is a pylint bug, there's an upstream report
+ g(['a'], run_concurrent=False)
+
+ test = self.profile.test_list[grouptools.join('foo', 'a')]
+ assert test.run_concurrent is False
+
+ def test_name_as_str(self):
+ """if args is a string it is not joined.
+
+ This is a "feature" of glean, and no longer needs to be protected
+ whenever glean dies.
+ """
+ with self.profile.group_manager(GleanTest, 'foo') as g:
+ g('abc')
+
+ assert grouptools.join('foo', 'abc') in self.profile.test_list
+
+
+class TestTestDict(object):
+ """Tests for the TestDict object."""
+
+ test = None
+
+ def setup(self):
+ self.test = profile.TestDict()
+
+ @pytest.mark.parametrize(
+ "arg",
+ [None, utils.Test(['foo']), ['a'], {'a': 1}],
+ ids=six.text_type)
+ def test_key_not_string(self, arg):
+ """profile.TestDict: If key value isn't a string an exception is raised.
+
+ This throws a few different things at the key value and expects an
+ error to be raised. It isn't a perfect test, but it was the best I
+ could come up with.
+ """
+ with pytest.raises(exceptions.PiglitFatalError):
+ self.test[arg] = utils.Test(['foo'])
+
+ def test_reassignment(self):
+ """reassigning a key raises an exception."""
+ self.test['foo'] = utils.Test(['foo'])
+ with pytest.raises(exceptions.PiglitFatalError):
+ self.test['foo'] = utils.Test(['foo', 'bar'])
+
+ class TestAllowReassignment(object):
+ """Tests for TestDict.allow_reassignment."""
+
+ @pytest.fixture
+ def test(self):
+ return profile.TestDict()
+
+ @pytest.fixture
+ def prof(self):
+ return profile.TestProfile()
+
+ def test_case_insensitve(self, test):
+ """reassigning a key raises an exception (capitalization is
+ ignored)."""
+ test['foo'] = utils.Test(['foo'])
+ with pytest.raises(exceptions.PiglitFatalError):
+ test['Foo'] = utils.Test(['foo', 'bar'])
+
+ def test_simple(self, test):
+ """profile.TestDict.allow_reassignment works."""
+ test['a'] = utils.Test(['foo'])
+ with test.allow_reassignment:
+ test['a'] = utils.Test(['bar'])
+
+ assert test['a'].command == ['bar']
+
+ def test_with_groupmanager(self, prof):
+ """profile.TestProfile: allow_reassignment wrapper works with
+ groupmanager.
+ """
+ testname = grouptools.join('a', 'b')
+ prof.test_list[testname] = utils.Test(['foo'])
+ with prof.allow_reassignment:
+ with prof.group_manager(utils.Test, 'a') as g:
+ g(['bar'], 'b')
+
+ assert prof.test_list[testname].command == ['bar']
+
+ def test_stacked(self, test):
+ """profile.profile.TestDict.allow_reassignment: check stacking
+ cornercase.
+
+ There is an odd corner case in the original (obvious)
+ implementation of this function, If one opens two context managers
+ and then returns from the inner one assignment will not be allowed,
+ even though one is still inside the first context manager.
+ """
+ test['a'] = utils.Test(['foo'])
+ with test.allow_reassignment:
+ with test.allow_reassignment:
+ pass
+ test['a'] = utils.Test(['bar'])
+
+ assert test['a'].command == ['bar']
diff --git a/unittests/framework/utils.py b/unittests/framework/utils.py
new file mode 100644
index 0000000..bb3a191
--- /dev/null
+++ b/unittests/framework/utils.py
@@ -0,0 +1,45 @@
+# encoding=utf-8
+# Copyright © 2016 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.
+
+"""Utility functions, classes, and constants for testing framework.
+
+This is only piglit specific data and functions.
+"""
+
+from __future__ import (
+ absolute_import, division, print_function, unicode_literals
+)
+
+from framework.test.base import Test as _Test
+
+
+class Test(_Test):
+ """A Test dericed class with a stub interpret_result.
+
+ This class provides a way to test the Test class.
+ """
+
+ def interpret_result(self):
+ pass
+
+ def __repr__(self):
+ return "Test({}, run_concurrent={})".format(
+ self.command, self.run_concurrent)
diff --git a/unittests/profile_tests.py b/unittests/profile_tests.py
deleted file mode 100644
index d190feb..0000000
--- a/unittests/profile_tests.py
+++ /dev/null
@@ -1,376 +0,0 @@
-# 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.
-
-""" Provides test for the framework.profile modules """
-
-from __future__ import (
- absolute_import, division, print_function, unicode_literals
-)
-import sys
-import copy
-
-try:
- from unittest import mock
-except ImportError:
- import mock
-
-import nose.tools as nt
-
-from . import utils
-from framework import grouptools, dmesg, profile, exceptions, options, exceptions
-from framework.test import GleanTest
-
-# Don't print sys.stderr to the console
-sys.stderr = sys.stdout
-
-
- at utils.nose.no_error
-def test_initialize_testprofile():
- """profile.TestProfile: class initializes"""
- profile.TestProfile()
-
-
- at nt.raises(exceptions.PiglitFatalError)
-def test_load_test_profile_no_profile():
- """profile.load_test_profile: Loading a module with no profile name exits
-
- Because load_test_profile uses test.{} to load a module we need a module in
- tests that doesn't have a profile attribute. The only module that currently
- meets that requirement is __init__.py
-
- """
- profile.load_test_profile('__init__')
-
-
- at nt.raises(exceptions.PiglitFatalError)
-def test_load_test_profile_no_module():
- """profile.load_test_profile: Trying to load a non-existant module exits"""
- profile.load_test_profile('this_module_will_never_ever_exist')
-
-
-def test_load_test_profile_returns():
- """profile.load_test_profile: returns a TestProfile instance"""
- profile_ = profile.load_test_profile('sanity')
- nt.ok_(isinstance(profile_, profile.TestProfile))
-
-
-def test_testprofile_default_dmesg():
- """profile.TestProfile: Dmesg initializes False"""
- profile_ = profile.TestProfile()
- nt.ok_(isinstance(profile_.dmesg, dmesg.DummyDmesg))
-
-
- at utils.nose.Skip.platform('linux')
-def test_testprofile_set_dmesg_true():
- """profile.TestProfile: Dmesg returns an appropriate dmesg is set to True"""
- profile_ = profile.TestProfile()
- profile_.dmesg = True
- nt.ok_(isinstance(profile_.dmesg, dmesg.LinuxDmesg))
-
-
- at utils.nose.Skip.platform('linux')
-def test_testprofile_set_dmesg_false():
- """profile.TestProfile: Dmesg returns a DummyDmesg if set to False"""
- profile_ = profile.TestProfile()
- profile_.dmesg = True
- profile_.dmesg = False
- nt.ok_(isinstance(profile_.dmesg, dmesg.DummyDmesg))
-
-
-def test_testprofile_update_test_list():
- """profile.TestProfile.update(): updates TestProfile.test_list"""
- profile1 = profile.TestProfile()
- group1 = grouptools.join('group1', 'test1')
- group2 = grouptools.join('group1', 'test2')
-
- profile1.test_list[group1] = utils.piglit.Test(['test1'])
-
-
- profile2 = profile.TestProfile()
- profile2.test_list[group1] = utils.piglit.Test(['test3'])
- profile2.test_list[group2] = utils.piglit.Test(['test2'])
-
- with profile1.allow_reassignment:
- profile1.update(profile2)
-
- nt.assert_dict_equal(dict(profile1.test_list), dict(profile2.test_list))
-
-
-class TestPrepareTestListMatches(object):
- """Create tests for TestProfile.prepare_test_list filtering"""
- def __init__(self):
- self.data = profile.TestDict()
- self.data[grouptools.join('group1', 'test1')] = utils.piglit.Test(['thingy'])
- self.data[grouptools.join('group1', 'group3', 'test2')] = utils.piglit.Test(['thing'])
- self.data[grouptools.join('group3', 'test5')] = utils.piglit.Test(['other'])
- self.data[grouptools.join('group4', 'Test9')] = utils.piglit.Test(['is_caps'])
- self.opts = None
- self.__patcher = mock.patch('framework.profile.options.OPTIONS',
- new_callable=options._Options)
-
- def setup(self):
- self.opts = self.__patcher.start()
-
- def teardown(self):
- self.__patcher.stop()
-
- def test_matches_filter_mar_1(self):
- """profile.TestProfile.prepare_test_list: 'not env.filter or matches_any_regex()' env.filter is False
-
- Nothing should be filtered.
-
- """
- profile_ = profile.TestProfile()
- profile_.test_list = self.data
- profile_._prepare_test_list()
-
- nt.assert_dict_equal(dict(profile_.test_list), dict(self.data))
-
- def test_matches_filter_mar_2(self):
- """profile.TestProfile.prepare_test_list: 'not env.filter or matches_any_regex()' mar is False"""
- self.opts.include_filter = ['test5']
-
- profile_ = profile.TestProfile()
- profile_.test_list = self.data
- profile_._prepare_test_list()
-
- baseline = {grouptools.join('group3', 'test5'): utils.piglit.Test(['other'])}
-
- nt.assert_dict_equal(dict(profile_.test_list), baseline)
-
- def test_matches_env_exclude(self):
- """profile.TestProfile.prepare_test_list: 'not path in env.exclude_tests'"""
- self.opts.exclude_tests.add(grouptools.join('group3', 'test5'))
-
- baseline = copy.deepcopy(self.data)
- del baseline[grouptools.join('group3', 'test5')]
-
- profile_ = profile.TestProfile()
- profile_.test_list = self.data
- profile_._prepare_test_list()
-
- nt.assert_dict_equal(dict(profile_.test_list), dict(baseline))
-
- def test_matches_exclude_mar(self):
- """profile.TestProfile.prepare_test_list: 'not matches_any_regexp()'"""
- self.opts.exclude_filter = ['test5']
-
- baseline = copy.deepcopy(self.data)
- del baseline[grouptools.join('group3', 'test5')]
-
- profile_ = profile.TestProfile()
- profile_.test_list = self.data
- profile_._prepare_test_list()
-
- nt.assert_dict_equal(dict(profile_.test_list), dict(baseline))
-
- def test_matches_include_caps(self):
- """profile.TestProfile.prepare_test_list: matches capitalized tests"""
- self.opts.exclude_filter = ['test9']
-
- profile_ = profile.TestProfile()
- profile_.test_list = self.data
- profile_._prepare_test_list()
-
- nt.assert_not_in(grouptools.join('group4', 'Test9'), profile_.test_list)
-
-
- at utils.nose.no_error
-def test_testprofile_group_manager_no_name_args_eq_one():
- """profile.TestProfile.group_manager: no name and len(args) == 1 is valid"""
- prof = profile.TestProfile()
- with prof.group_manager(utils.piglit.Test, 'foo') as g:
- g(['a'])
-
-
-def test_testprofile_group_manager_no_name_args_gt_one():
- """profile.TestProfile.group_manager: no name and len(args) > 1 is valid"""
- prof = profile.TestProfile()
- with prof.group_manager(utils.piglit.Test, 'foo') as g:
- g(['a', 'b'])
-
- nt.assert_in(grouptools.join('foo', 'a b'), prof.test_list)
-
-
- at utils.nose.no_error
-def test_testprofile_group_manager_name():
- """profile.TestProfile.group_manager: name plus len(args) > 1 is valid"""
- prof = profile.TestProfile()
- with prof.group_manager(utils.piglit.Test, 'foo') as g:
- g(['a', 'b'], 'a')
-
-
-def test_testprofile_group_manager_is_added():
- """profile.TestProfile.group_manager: Tests are added to the profile"""
- prof = profile.TestProfile()
- with prof.group_manager(utils.piglit.Test, 'foo') as g:
- g(['a', 'b'], 'a')
-
- nt.assert_in(grouptools.join('foo', 'a'), prof.test_list)
-
-
-def test_testprofile_groupmanager_kwargs():
- """profile.TestProfile.group_manager: Extra kwargs are passed to the Test"""
- prof = profile.TestProfile()
- with prof.group_manager(utils.piglit.Test, 'foo') as g:
- g(['a'], run_concurrent=True)
-
- test = prof.test_list[grouptools.join('foo', 'a')]
- nt.assert_equal(test.run_concurrent, True)
-
-
-def test_testprofile_groupmanager_default_args():
- """profile.TestProfile.group_manager: group_manater kwargs are passed to the Test"""
- prof = profile.TestProfile()
- with prof.group_manager(utils.piglit.Test, 'foo', run_concurrent=True) as g:
- g(['a'])
-
- test = prof.test_list[grouptools.join('foo', 'a')]
- nt.assert_equal(test.run_concurrent, True)
-
-
-def test_testprofile_groupmanager_kwargs_overwrite():
- """profile.TestProfile.group_manager: default_args are overwritten by kwargs"""
- prof = profile.TestProfile()
- with prof.group_manager(utils.piglit.Test, 'foo', run_concurrent=True) as g:
- g(['a'], run_concurrent=False)
-
- test = prof.test_list[grouptools.join('foo', 'a')]
- nt.assert_equal(test.run_concurrent, False)
-
-
-def test_testprofile_groupmanager_name_str():
- """profile.TestProfile.group_manager: if args is a string it is not joined"""
- prof = profile.TestProfile()
- # Yes, this is really about supporting gleantest anyway.
- with prof.group_manager(GleanTest, 'foo') as g:
- g('abc')
-
- nt.ok_(grouptools.join('foo', 'abc') in prof.test_list)
-
-
- at nt.raises(exceptions.PiglitFatalError)
-def test_testdict_key_not_string():
- """profile.TestDict: If key value isn't a string an exception is raised.
-
- This throws a few different things at the key value and expects an error to
- be raised. It isn't a perfect test, but it was the best I could come up
- with.
-
- """
- test = profile.TestDict()
-
- for x in [None, utils.piglit.Test(['foo']), ['a'], {'a': 1}]:
- test[x] = utils.piglit.Test(['foo'])
-
-
- at nt.raises(exceptions.PiglitFatalError)
-def test_testdict_value_not_valid():
- """profile.TestDict: If the value isn't a Test an exception is raised.
-
- Like the key test this isn't perfect, but it does try the common mistakes.
-
- """
- test = profile.TestDict()
-
- for x in [{}, 'a']:
- test['foo'] = x
-
-
- at nt.raises(exceptions.PiglitFatalError)
-def test_testdict_reassignment():
- """profile.TestDict: reassigning a key raises an exception"""
- test = profile.TestDict()
- test['foo'] = utils.piglit.Test(['foo'])
- test['foo'] = utils.piglit.Test(['foo', 'bar'])
-
-
- at nt.raises(exceptions.PiglitFatalError)
-def test_testdict_reassignment_lower():
- """profile.TestDict: reassigning a key raises an exception (capitalization is ignored)"""
- test = profile.TestDict()
- test['foo'] = utils.piglit.Test(['foo'])
- test['Foo'] = utils.piglit.Test(['foo', 'bar'])
-
-
-def test_testdict_allow_reassignment():
- """profile.TestDict: allow_reassignment works"""
- test = profile.TestDict()
- test['a'] = utils.piglit.Test(['foo'])
- with test.allow_reassignment:
- test['a'] = utils.piglit.Test(['bar'])
-
- nt.ok_(test['a'].command == ['bar'])
-
-
-def test_testprofile_allow_reassignment():
- """profile.TestProfile: allow_reassignment wrapper works"""
- prof = profile.TestProfile()
- prof.test_list['a'] = utils.piglit.Test(['foo'])
- with prof.allow_reassignment:
- prof.test_list['a'] = utils.piglit.Test(['bar'])
-
- nt.ok_(prof.test_list['a'].command == ['bar'])
-
-
-def test_testprofile_allow_reassignment_with_groupmanager():
- """profile.TestProfile: allow_reassignment wrapper works with groupmanager"""
- testname = grouptools.join('a', 'b')
- prof = profile.TestProfile()
- prof.test_list[testname] = utils.piglit.Test(['foo'])
- with prof.allow_reassignment:
- with prof.group_manager(utils.piglit.Test, 'a') as g:
- g(['bar'], 'b')
-
- nt.ok_(prof.test_list[testname].command == ['bar'])
-
-
-def test_testprofile_allow_reassignemnt_stacked():
- """profile.profile.TestDict.allow_reassignment: check stacking cornercase
-
- There is an odd corner case in the original (obvious) implementation of this
- function, If one opens two context managers and then returns from the inner
- one assignment will not be allowed, even though one is still inside the
- first context manager.
-
- """
- test = profile.TestDict()
- test['a'] = utils.piglit.Test(['foo'])
- with test.allow_reassignment:
- with test.allow_reassignment:
- pass
- test['a'] = utils.piglit.Test(['bar'])
-
- nt.ok_(test['a'].command == ['bar'])
-
-
- at nt.raises(exceptions.PiglitFatalError)
-def test_testdict_update_reassignment():
- """profile.TestDict.update: Does not implictly allow reassignment"""
- test1 = utils.piglit.Test(['test1'])
- test2 = utils.piglit.Test(['test2'])
-
- td1 = profile.TestDict()
- td1['test1'] = test1
-
- td2 = profile.TestDict()
- td2['test1'] = test2
-
- td1.update(td2)
--
2.9.0
More information about the Piglit
mailing list