def test_with_user(self, repo: Repo, tmpdir: TempDirectory): repo.commit_content('a') clone = Repo.clone(repo, 'clone', User('Foo', '*****@*****.**')) tmpdir.check('clone', 'repo') config = (clone.path / '.git' / 'config').read_text() assert 'name = Foo' in config assert 'email = [email protected]' in config
def test_clone(self, tmpdir: TempDirectory): root = Path(tmpdir.path) upstream = Repo.make(root / 'upstream') upstream.commit_content('a') clone = Repo.clone(upstream, root / 'clone') tmpdir.check('clone', 'upstream') config = (clone.path / '.git' / 'config').read_text() assert 'name = Giterator' in config assert 'email = [email protected]' in config
def test_evaulate_write(self): dir = TempDirectory() d = TestContainer('parsed',FileBlock('foo','content','write')) d.evaluate_with(Files('td'),globs={'td':dir}) compare([C(FileResult, passed=True, expected=None, actual=None)], [r.evaluated for r in d]) dir.check('foo') compare(dir.read('foo'),'content')
def test_evaulate_write(self): dir = TempDirectory() d = TestContainer('parsed',FileBlock('foo','content','write')) d.evaluate_with(Files('td'),globs={'td':dir}) compare([C(FileResult, passed=True, expected=None, actual=None)], [r.evaluated for r in d]) dir.check('foo') compare(dir.read('foo', 'ascii'), 'content')
class HomeDirTest(unittest.TestCase): def setUp(self): self.temp_dir = TempDirectory(create=True) self.home = PathHomeDir(self.temp_dir.path) def tearDown(self): self.temp_dir.cleanup() def test_read(self): self.temp_dir.write("filename", "contents") self.assertEquals(self.home.read("filename"), "contents") def test_write(self): self.temp_dir.write("existing_file", "existing_contents") self.home.write("new_file", "contents") self.home.write("existing_file", "new_contents") self.assertEquals(self.temp_dir.read("existing_file"), "new_contents") self.assertEquals(self.temp_dir.read("new_file"), "contents") def test_config_file(self): with collect_outputs() as outputs: self.home.write_config_file("new config") self.temp_dir.check(".cosmosrc") self.assertEquals(self.home.read_config_file(), "new config") self.assertIn("Settings saved", outputs.stdout.getvalue()) file_mode = os.stat(self.temp_dir.getpath(".cosmosrc")).st_mode self.assertEquals(file_mode, stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR) def test_override_config_file(self): with collect_outputs(): other_config = self.temp_dir.write("path/other", "config") self.assertEquals( self.home.read_config_file(filename_override=other_config), "config") def test_warn_on_unprotected_config_file(self): with collect_outputs() as outputs: self.home.write_config_file("new config") config_path = self.temp_dir.getpath(".cosmosrc") os.chmod(config_path, 0777) self.home.read_config_file() assertFunc = (self.assertNotIn if os.name=='nt' else self.assertIn) assertFunc("WARNING", outputs.stderr.getvalue()) def test_last_cluster(self): self.home.write_last_cluster("0000000") self.temp_dir.check(".cosmoslast") self.assertEquals(self.home.read_last_cluster(), "0000000")
class HomeDirTest(unittest.TestCase): def setUp(self): self.temp_dir = TempDirectory(create=True) self.home = PathHomeDir(self.temp_dir.path) def tearDown(self): self.temp_dir.cleanup() def test_read(self): self.temp_dir.write("filename", "contents") self.assertEquals(self.home.read("filename"), "contents") def test_write(self): self.temp_dir.write("existing_file", "existing_contents") self.home.write("new_file", "contents") self.home.write("existing_file", "new_contents") self.assertEquals(self.temp_dir.read("existing_file"), "new_contents") self.assertEquals(self.temp_dir.read("new_file"), "contents") def test_config_file(self): with collect_outputs() as outputs: self.home.write_config_file("new config") self.temp_dir.check(".cosmosrc") self.assertEquals(self.home.read_config_file(), "new config") self.assertIn("Settings saved", outputs.stdout.getvalue()) file_mode = os.stat(self.temp_dir.getpath(".cosmosrc")).st_mode self.assertEquals(file_mode, stat.S_IFREG | stat.S_IRUSR | stat.S_IWUSR) def test_override_config_file(self): with collect_outputs(): other_config = self.temp_dir.write("path/other", "config") self.assertEquals( self.home.read_config_file(filename_override=other_config), "config") def test_warn_on_unprotected_config_file(self): with collect_outputs() as outputs: self.home.write_config_file("new config") config_path = self.temp_dir.getpath(".cosmosrc") os.chmod(config_path, 0777) self.home.read_config_file() assertFunc = (self.assertNotIn if os.name == 'nt' else self.assertIn) assertFunc("WARNING", outputs.stderr.getvalue()) def test_last_cluster(self): self.home.write_last_cluster("0000000") self.temp_dir.check(".cosmoslast") self.assertEquals(self.home.read_last_cluster(), "0000000")
class Test_directory_fill_helpers(TestCase): def setUp(self): self.testDir = TempDirectory() def tearDown(self): self.testDir.cleanup() def test_generate_filenames_one_file(self): fileNames = generate_filenames(1) self.assertTrue(fileNames == ['file0']) def test_generate_filenames_number_out_of_range(self): self.assertRaises(ValueError, generate_filenames, 0) self.assertRaises(ValueError, generate_filenames, 11) def test_generate_filenames_two_files(self): fileNames = generate_filenames(2) self.assertTrue(fileNames == ['file0', 'file1']) def test_genertate_file_contents_one_file(self): fileContents = generate_file_contents(1) self.assertTrue(fileContents == ['']) def test_generate_file_contents_number_out_of_range(self): self.assertRaises(ValueError, generate_file_contents, 0) self.assertRaises(ValueError, generate_file_contents, 11) def test_generate_file_contents_two_files(self): fileContents = generate_file_contents(2) self.assertTrue(fileContents == ['', '1']) def test_write_test_files_one_file(self): fileNames = generate_filenames(1) fileContents = generate_file_contents(1) files = zip(fileNames, fileContents) write_files(self.testDir, files) self.testDir.check(*fileNames) def test_write_test_files_ten_files(self): fileNames = generate_filenames(10) fileContents = generate_file_contents(10) files = zip(fileNames, fileContents) write_files(self.testDir, files) self.testDir.check(*fileNames) def test_create_files_one_file(self): create_files(self.testDir, 1) self.testDir.check(*generate_filenames(1)) def test_create_files_ten_files(self): create_files(self.testDir, 10) self.testDir.check(*generate_filenames(10)) def test_generate_dirnames_one_dir(self): dirNames = generate_dirnames(1) self.assertTrue(dirNames == ['dir0']) def test_generate_dirnames_two_dirs(self): dirNames = generate_dirnames(2) self.assertTrue(dirNames == ['dir0', 'dir1']) def test_generate_dirnames_number_out_of_range(self): self.assertRaises(ValueError, generate_dirnames, 0) self.assertRaises(ValueError, generate_dirnames, 11) def test_create_directories_one_dir(self): create_directories(self.testDir, 1) self.testDir.check(*generate_dirnames(1)) def test_create_directories_ten_dirs(self): create_directories(self.testDir, 10) self.testDir.check(*generate_dirnames(10))
class TestTestcase(): """ Test the testcase class """ def __init__(self): self.tempdir = TempDirectory() self.work_dir = self.tempdir.path def setUp(self): self.dt = {'type': 'string', 'include': '#include <stdio.h>\n#include "foo.h"\n#include <stdlib.h>', 'define': '', 'init': '', 'activation': '' } self.testcase_id = 42 self.function_name = 'test_function_name' self.c_types = [1, 2] setting = Setting(42, 'setting', 0, self.dt, 'code', 21, self.work_dir) self.settings = [setting] self.ret_val = 'ret_type' self.fun_header = '#include <stdio.h>\n' def tearDown(self): self.tempdir.cleanup() def test_get_id(self): """ get_id should return the supplied id """ TEST_ID = 21 tc = Testcase(TEST_ID, self.function_name, self.settings, self.work_dir, self.c_types, self.ret_val, self.fun_header) assert_equal(tc.get_id(), TEST_ID, 'ID is not matching') def test_get_setting(self): """ get_setting should return supplied setting """ TEST_SETTING = self.settings tc = Testcase(self.testcase_id, self.function_name, TEST_SETTING, self.work_dir, self.c_types, self.ret_val, self.fun_header) assert_equal(tc.get_settings(), TEST_SETTING, 'Setting is not matching') def test_get_name(self): """ get_name should return supplied name """ TEST_NAME = 'TC_bar_42' tc = Testcase(self.testcase_id, 'bar', self.settings, self.work_dir, self.c_types, self.ret_val, self.fun_header) assert_equal(tc.get_name(), TEST_NAME, 'Name is not matching: {0} != {1}'.format(tc.get_name(), TEST_NAME)) def test_generate_files(self): """ generate_files should create the header file for this testcase """ tc = Testcase(self.testcase_id, self.function_name, self.settings, self.work_dir, self.c_types, self.ret_val, self.fun_header) tc.generate_files() self.tempdir.check('TC_test_function_name_42.cpp', 'TC_test_function_name_42.h')
class TestSetting(): """ Test the setting class """ def setUp(self): """ Setup test fixtures """ self.setting_id = 42 self.setting_name = 'test_setting_name' self.setting_position = 0 self.dt = {'type': 'string', 'include': '#include <stdio.h>\n#include "foo.h"\n#include <stdlib.h>', 'define': '', 'init': '', 'activation': ''} self.setting_code = 'code' self.function_ref = 1 self.tempdir = TempDirectory() self.work_dir = self.tempdir.path def tearDown(self): """ Remove artefacts """ self.tempdir.cleanup() def test_get_name(self): """get_name should return the supplied name""" TEST_NAME = 'test_name' setting = Setting(self.setting_id, TEST_NAME, self.setting_position, self.dt, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_name(), TEST_NAME) def test_get_id(self): """get_id should return the supplied id""" TEST_ID = 43 setting = Setting(TEST_ID, self.setting_name, self.setting_position, self.dt, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_id(), TEST_ID) def test_get_position(self): """get_position should return the supplied position""" TEST_POSITION = 1 setting = Setting(self.setting_id, self.setting_name, TEST_POSITION, self.dt, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_position(), TEST_POSITION) def test_get_code(self): """get_code should return the supplied code""" TEST_CODE = 'if (foo) { bar; }' setting = Setting(self.setting_id, self.setting_name, self.setting_position, self.dt, TEST_CODE, self.function_ref, self.work_dir) assert_equal(setting.get_code(), TEST_CODE) def test_get_function_ref(self): """get_function_ref should return the supplied function_ref""" TEST_F_REF = 22 setting = Setting(self.setting_id, self.setting_name, self.setting_position, self.dt, self.setting_code, TEST_F_REF, self.work_dir) assert_equal(setting.get_function_ref(), TEST_F_REF) def test_get_datatype(self): """get_datatype should return the supplied datatype record""" TEST_DT = self.dt setting = Setting(self.setting_id, self.setting_name, self.setting_position, TEST_DT, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_datatype(), TEST_DT) def test_ballista_settings_get_removed(self): """all ballista includes should be removed from the datatype include string """ setting = Setting(self.setting_id, self.setting_name, self.setting_position, self.dt, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_datatype()['include'], '#include <stdio.h>\n\n#include <stdlib.h>') def test_generate_files(self): """ generating the setting files should create header and cpp files """ setting = Setting(self.setting_id, 't_name_42', self.setting_position, self.dt, self.setting_code, self.function_ref, self.work_dir) setting.generate_files() self.tempdir.check('t_name_42.cpp', 't_name_42.h')
class TestTestcase(): """ Test the testcase class """ def __init__(self): self.tempdir = TempDirectory() self.work_dir = self.tempdir.path def setUp(self): self.dt = { 'type': 'string', 'include': '#include <stdio.h>\n#include "foo.h"\n#include <stdlib.h>', 'define': '', 'init': '', 'activation': '' } self.testcase_id = 42 self.function_name = 'test_function_name' self.c_types = [1, 2] setting = Setting(42, 'setting', 0, self.dt, 'code', 21, self.work_dir) self.settings = [setting] self.ret_val = 'ret_type' self.fun_header = '#include <stdio.h>\n' def tearDown(self): self.tempdir.cleanup() def test_get_id(self): """ get_id should return the supplied id """ TEST_ID = 21 tc = Testcase(TEST_ID, self.function_name, self.settings, self.work_dir, self.c_types, self.ret_val, self.fun_header) assert_equal(tc.get_id(), TEST_ID, 'ID is not matching') def test_get_setting(self): """ get_setting should return supplied setting """ TEST_SETTING = self.settings tc = Testcase(self.testcase_id, self.function_name, TEST_SETTING, self.work_dir, self.c_types, self.ret_val, self.fun_header) assert_equal(tc.get_settings(), TEST_SETTING, 'Setting is not matching') def test_get_name(self): """ get_name should return supplied name """ TEST_NAME = 'TC_bar_42' tc = Testcase(self.testcase_id, 'bar', self.settings, self.work_dir, self.c_types, self.ret_val, self.fun_header) assert_equal( tc.get_name(), TEST_NAME, 'Name is not matching: {0} != {1}'.format(tc.get_name(), TEST_NAME)) def test_generate_files(self): """ generate_files should create the header file for this testcase """ tc = Testcase(self.testcase_id, self.function_name, self.settings, self.work_dir, self.c_types, self.ret_val, self.fun_header) tc.generate_files() self.tempdir.check('TC_test_function_name_42.cpp', 'TC_test_function_name_42.h')
class TestSetting(): """ Test the setting class """ def setUp(self): """ Setup test fixtures """ self.setting_id = 42 self.setting_name = 'test_setting_name' self.setting_position = 0 self.dt = { 'type': 'string', 'include': '#include <stdio.h>\n#include "foo.h"\n#include <stdlib.h>', 'define': '', 'init': '', 'activation': '' } self.setting_code = 'code' self.function_ref = 1 self.tempdir = TempDirectory() self.work_dir = self.tempdir.path def tearDown(self): """ Remove artefacts """ self.tempdir.cleanup() def test_get_name(self): """get_name should return the supplied name""" TEST_NAME = 'test_name' setting = Setting(self.setting_id, TEST_NAME, self.setting_position, self.dt, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_name(), TEST_NAME) def test_get_id(self): """get_id should return the supplied id""" TEST_ID = 43 setting = Setting(TEST_ID, self.setting_name, self.setting_position, self.dt, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_id(), TEST_ID) def test_get_position(self): """get_position should return the supplied position""" TEST_POSITION = 1 setting = Setting(self.setting_id, self.setting_name, TEST_POSITION, self.dt, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_position(), TEST_POSITION) def test_get_code(self): """get_code should return the supplied code""" TEST_CODE = 'if (foo) { bar; }' setting = Setting(self.setting_id, self.setting_name, self.setting_position, self.dt, TEST_CODE, self.function_ref, self.work_dir) assert_equal(setting.get_code(), TEST_CODE) def test_get_function_ref(self): """get_function_ref should return the supplied function_ref""" TEST_F_REF = 22 setting = Setting(self.setting_id, self.setting_name, self.setting_position, self.dt, self.setting_code, TEST_F_REF, self.work_dir) assert_equal(setting.get_function_ref(), TEST_F_REF) def test_get_datatype(self): """get_datatype should return the supplied datatype record""" TEST_DT = self.dt setting = Setting(self.setting_id, self.setting_name, self.setting_position, TEST_DT, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_datatype(), TEST_DT) def test_ballista_settings_get_removed(self): """all ballista includes should be removed from the datatype include string """ setting = Setting(self.setting_id, self.setting_name, self.setting_position, self.dt, self.setting_code, self.function_ref, self.work_dir) assert_equal(setting.get_datatype()['include'], '#include <stdio.h>\n\n#include <stdlib.h>') def test_generate_files(self): """ generating the setting files should create header and cpp files """ setting = Setting(self.setting_id, 't_name_42', self.setting_position, self.dt, self.setting_code, self.function_ref, self.work_dir) setting.generate_files() self.tempdir.check('t_name_42.cpp', 't_name_42.h')