def run_fixture(cls, test_fixture, expect_relation): """Set class variables for next fixture run.""" test_fixture_name = test_fixture.__name__ overrides = { 'LOG_FILEBASE': 'test_runner_test__' + test_fixture_name, 'LOG_DIR': '.' } result = TestRunner.main(test_case_list=[test_fixture], default_binding_overrides=overrides) if (result == 0) != (expect_relation == 'VALID'): sys.exit(-1) journal_path = os.path.join('.', overrides['LOG_FILEBASE'] + '.journal') with open(journal_path, 'rb') as stream: cls.journal_data = stream.read() cls.expected_summary_relation = expect_relation cls.expected_fixture_name = test_fixture_name overrides['LOG_FILEBASE'] = 'test_runner_test__JournalContentTest' result = TestRunner.main(test_case_list=[JournalContentTest], default_binding_overrides=overrides) if result: sys.exit(result)
def test_init_bindings_builder(self): builder = ConfigurationBindingsBuilder() TestRunner.global_runner().init_bindings_builder(builder) bindings = builder.build() self.assertEquals('.', bindings.get('log_dir')) self.assertEquals(os.path.splitext(os.path.basename(__main__.__file__))[0], bindings.get('log_filebase'))
def test_init_argument_parser(self): parser = argparse.ArgumentParser() TestRunner.global_runner().initArgumentParser(parser) args = parser.parse_args() self.assertEquals('.', args.log_dir) self.assertEquals(os.path.splitext(os.path.basename(__main__.__file__))[0], args.log_filebase)
def test_shared_data_with_extra_bindings(self): """Tests global singleton data management provided by TestRunner.""" # pylint: disable=missing-docstring # pylint: disable=too-few-public-methods class MyData(object): @classmethod def init_bindings_builder(cls, builder, defaults=None): defaults = defaults or {} builder.add_argument('--data', default=defaults.get( 'TEST_DATA', 'MyData')) @property def bindings(self): return self.__bindings def __init__(self, bindings): self.__bindings = bindings # Configures from our runner's properties. a = TestRunner.get_shared_data(MyData) self.assertEqual('MyData', a.bindings.get('data')) # Acts as singleton b = TestRunner.get_shared_data(MyData) self.assertEqual(a, b)
def test_init_argument_parser(self): parser = argparse.ArgumentParser() TestRunner.global_runner().initArgumentParser(parser) args = parser.parse_args() self.assertEquals(args.log_dir, '.') self.assertEquals( args.log_filebase, os.path.splitext(os.path.basename(__main__.__file__))[0])
def test_init_bindings_builder(self): """Verify the builtin bindings.""" builder = ConfigurationBindingsBuilder() TestRunner.global_runner().init_bindings_builder(builder) bindings = builder.build() self.assertEquals('.', bindings.get('log_dir')) self.assertEquals(os.path.splitext(os.path.basename(__main__.__file__))[0], bindings.get('log_filebase')) # While not necessarily a design criteria, the implementation has all # the bindings added by all the fixtures. self.assertEquals('MyTestParamValue', bindings.get('TEST_PARAM')) self.assertEquals('MyTestBindingValue', bindings.get('TEST_BINDING'))
def test_init_bindings_builder(self): """Verify the builtin bindings.""" builder = ConfigurationBindingsBuilder() TestRunner.global_runner().init_bindings_builder(builder) bindings = builder.build() self.assertEqual('.', bindings.get('log_dir')) self.assertEqual( os.path.splitext(os.path.basename(__main__.__file__))[0], bindings.get('log_filebase')) # While not necessarily a design criteria, the implementation has all # the bindings added by all the fixtures. self.assertEqual('MyTestParamValue', bindings.get('TEST_PARAM')) self.assertEqual('MyTestBindingValue', bindings.get('TEST_BINDING'))
def test_bindings_from_config(self): """Verify bindings from the implied config file in the TestRunner. We set the config file in the fixture forking this test. """ bindings = TestRunner.global_runner().bindings self.assertEqual('tests/base/bindings_test', bindings.get('config_location'))
def test_bindings_from_config(self): """Verify bindings from the implied config file in the TestRunner. We set the config file in the fixture forking this test. """ bindings = TestRunner.global_runner().bindings self.assertEquals('tests/base/bindings_test', bindings.get('config_location'))
def test_shared_data_without_extra_bindings(self): """Tests global singleton data management provided by TestRunner.""" # pylint: disable=missing-docstring # pylint: disable=too-few-public-methods class MyData(object): @property def bindings(self): return self.__bindings def __init__(self, bindings): self.__bindings = bindings # Configures from our runner's properties. a = TestRunner.get_shared_data(MyData) self.assertEquals('MyTestBindingValue', a.bindings.get('test_binding')) # Acts as singleton b = TestRunner.get_shared_data(MyData) self.assertEquals(a, b)
def test_shared_data_without_extra_bindings(self): """Tests global singleton data management provided by TestRunner.""" # pylint: disable=missing-docstring # pylint: disable=too-few-public-methods class MyData(object): @property def bindings(self): return self.__bindings def __init__(self, bindings): self.__bindings = bindings # Configures from our runner's properties. a = TestRunner.get_shared_data(MyData) self.assertEqual('MyTestBindingValue', a.bindings.get('test_binding')) # Acts as singleton b = TestRunner.get_shared_data(MyData) self.assertEqual(a, b)
def test_bindings(self): """Verify bindings are set on the runner.""" bindings = TestRunner.global_runner().bindings self.assertEquals('.', bindings['LOG_DIR']) self.assertEquals( os.path.splitext(os.path.basename(__main__.__file__))[0], bindings['LOG_FILEBASE']) # While not necessarily a design criteria, the implementation has all # the bindings added by all the fixtures. self.assertEquals('MyTestParamValue', bindings.get('TEST_PARAM')) self.assertEquals('MyTestBindingValue', bindings.get('TEST_BINDING'))
def test_bindings(self): """Verify bindings are set on the runner.""" bindings = TestRunner.global_runner().bindings self.assertEqual('.', bindings['LOG_DIR']) self.assertEqual( os.path.splitext(os.path.basename(__main__.__file__))[0], bindings['LOG_FILEBASE']) # While not necessarily a design criteria, the implementation has all # the bindings added by all the fixtures. self.assertEqual('MyTestParamValue', bindings.get('TEST_PARAM')) self.assertEqual('MyTestBindingValue', bindings.get('TEST_BINDING'))
def test_shared_data_with_extra_bindings(self): """Tests global singleton data management provided by TestRunner.""" # pylint: disable=missing-docstring # pylint: disable=too-few-public-methods class MyData(object): @classmethod def init_bindings_builder(cls, builder, defaults=None): defaults = defaults or {} builder.add_argument( '--data', default=defaults.get('TEST_DATA', 'MyData')) @property def bindings(self): return self.__bindings def __init__(self, bindings): self.__bindings = bindings # Configures from our runner's properties. a = TestRunner.get_shared_data(MyData) self.assertEquals('MyData', a.bindings.get('data')) # Acts as singleton b = TestRunner.get_shared_data(MyData) self.assertEquals(a, b)
def run_fixture(cls, test_fixture, expect_relation): """Set class variables for next fixture run.""" test_fixture_name = test_fixture.__name__ overrides = {'LOG_FILEBASE': 'test_runner_test__' + test_fixture_name, 'LOG_DIR': '.'} result = TestRunner.main(test_case_list=[test_fixture], default_binding_overrides=overrides) if (result == 0) != (expect_relation == 'VALID'): sys.exit(-1) journal_path = os.path.join( '.', overrides['LOG_FILEBASE'] + '.journal') with open(journal_path, 'rb') as stream: cls.journal_data = stream.read() cls.expected_summary_relation = expect_relation cls.expected_fixture_name = test_fixture_name overrides['LOG_FILEBASE'] = 'test_runner_test__JournalContentTest' result = TestRunner.main(test_case_list=[JournalContentTest], default_binding_overrides=overrides) if result: sys.exit(result)
global in_test_main test_fixtures = [TestRunnerTest, TestParamFixture, TestBindingsFixture] argv = sys.argv old_config = os.environ.get('CITEST_CONFIG_PATH') os.environ['CITEST_CONFIG_PATH'] = os.path.join( os.path.dirname(__file__), 'bindings_test.config') try: in_test_main = True sys.argv = [ sys.argv[0], '--test_binding', 'MyTestBindingValue', '--test_param', 'MyTestParamValue' ] result = TestingTestRunner.main(test_case_list=test_fixtures) finally: in_test_main = False sys.argv = argv if old_config: os.environ['CITEST_CONFIG_PATH'] = old_config else: del os.environ['CITEST_CONFIG_PATH'] self.assertEquals(0, result) self.assertEquals(call_check, test_fixtures) self.assertEquals(1, TestingTestRunner.terminate_calls) if __name__ == '__main__': sys.exit(TestRunner.main(test_case_list=[TestRunnerTestCase]))
def test_bindings(self): self.assertEquals('.', TestRunner.global_runner().bindings['LOG_DIR']) self.assertEquals( os.path.splitext(os.path.basename(__main__.__file__))[0], TestRunner.global_runner().bindings['LOG_FILEBASE'])
def test_init_bindings_builder(self): builder = ConfigurationBindingsBuilder() TestRunner.global_runner().init_bindings_builder(builder) bindings = builder.build() self.assertEquals('.', bindings.get('log_dir')) self.assertEquals(os.path.splitext(os.path.basename(__main__.__file__))[0], bindings.get('log_filebase')) def test_init_argument_parser(self): parser = argparse.ArgumentParser() TestRunner.global_runner().initArgumentParser(parser) args = parser.parse_args() self.assertEquals('.', args.log_dir) self.assertEquals(os.path.splitext(os.path.basename(__main__.__file__))[0], args.log_filebase) def test_bindings(self): self.assertEquals('.', TestRunner.global_runner().bindings['LOG_DIR']) self.assertEquals( os.path.splitext(os.path.basename(__main__.__file__))[0], TestRunner.global_runner().bindings['LOG_FILEBASE']) if __name__ == '__main__': result = TestRunner.main(test_case_list=[TestRunnerTest]) if not tested_main: raise Exception("Test Failed.") sys.exit(result)
"""Test citest.base.TestRunner.main() invocation.""" global in_test_main test_fixtures = [TestRunnerTest, TestParamFixture, TestBindingsFixture] argv = sys.argv old_config = os.environ.get('CITEST_CONFIG_PATH') os.environ['CITEST_CONFIG_PATH'] = os.path.join( os.path.dirname(__file__), 'bindings_test.config') try: in_test_main = True sys.argv = [sys.argv[0], '--test_binding', 'MyTestBindingValue', '--test_param', 'MyTestParamValue'] result = TestingTestRunner.main(test_case_list=test_fixtures) finally: in_test_main = False sys.argv = argv if old_config: os.environ['CITEST_CONFIG_PATH'] = old_config else: del os.environ['CITEST_CONFIG_PATH'] self.assertEquals(0, result) self.assertEquals(call_check, test_fixtures) self.assertEquals(1, TestingTestRunner.terminate_calls) if __name__ == '__main__': sys.exit(TestRunner.main(test_case_list=[TestRunnerTestCase]))
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import argparse import os.path import sys import __main__ from citest.base import BaseTestCase from citest.base import TestRunner tested_main = False class BaseTestCaseTest(BaseTestCase): def test_logging(self): self.log_start_test() self.log_end_test(name='Test') if __name__ == '__main__': result = TestRunner.main(test_case_list=[BaseTestCaseTest]) if not tested_main: raise Exception("Test Failed.") sys.exit(result)
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import argparse import os.path import sys import __main__ from citest.base import BaseTestCase from citest.base import TestRunner tested_main = False class BaseTestCaseTest(BaseTestCase): def test_logging(self): self.log_start_test() self.log_end_test(name='Test') if __name__ == '__main__': result = TestRunner.main(test_case_list=[BaseTestCaseTest]) if not tested_main: raise Exception("Test Failed.") sys.exit(result)
class TestRunnerTest(BaseTestCase): def test_main(self): # Confirms that our tests run. global tested_main tested_main = True def test_init_argument_parser(self): parser = argparse.ArgumentParser() TestRunner.global_runner().initArgumentParser(parser) args = parser.parse_args() self.assertEquals(args.log_dir, '.') self.assertEquals( args.log_filebase, os.path.splitext(os.path.basename(__main__.__file__))[0]) def test_bindings(self): self.assertEquals('.', TestRunner.global_runner().bindings['LOG_DIR']) self.assertEquals( os.path.splitext(os.path.basename(__main__.__file__))[0], TestRunner.global_runner().bindings['LOG_FILEBASE']) if __name__ == '__main__': result = TestRunner.main(test_case_list=[TestRunnerTest]) if not tested_main: raise Exception("Test Failed.") sys.exit(result)