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 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)
"""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)
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)
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)
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]))