def test_generate_input(self): writer = Writer(self.data, content='random') config, param = writer.generate_input([['5fa34fc', 'a16e0bb','8924a5f'], ['abc', 'abc', 'xyz']]) self.assertEqual(config, expanduser('~/tmp/config.tar.gz')) tar = tarfile.open(expanduser(config)) tar.extractall(path=expanduser('./config')) tar.close() os.chdir('./config') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 3) self.assertEqual(param, expanduser('~/tmp/params.tar.gz')) tar = tarfile.open(expanduser(param)) tar.extractall(path=expanduser('./test-param')) tar.close() os.chdir('./test-param') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 3) self.assertItemsEqual(os.listdir('.'), ['cl-params-1.txt','cl-params-2.txt','cl-params-3.txt']) with open('cl-params-2.txt', 'r') as f: buf = f.read() self.assertIn("--tests 'abc$'", buf) self.assertIn('-o ~/tmp/out.csv', buf) self.assertIn('-f ~/tmp/config/cloud-config-2.xml', buf) self.assertIn('--cloud ~/storage-credentials.json clopper-storage', buf)
def test_config3(self): writer = Writer(self.data, content='') writer.get_config([None],3) num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1) config = os.listdir('.')[0] self.assertEqual(config, 'cloud-config-3.xml')
def test_get_current_params_simple(self): data = json.loads(self.data) writer = Writer(data, content = '') test_dict = writer.get_current_params() self.assertEqual(test_dict['-t'], data['CL-params']['-t']) self.assertEqual(test_dict['-o'], '~/tmp/out.csv') self.assertEqual(test_dict['-f'], data['CL-params']['-f']) self.assertEqual(test_dict['--cloud'], "~/storage-credentials.json clopper-storage") [self.assertNotIn(item, test_dict) for item in self.mapping]
def test_get_current_params_extended(self): data = json.loads(self.data) for item in self.mapping: data['CL-params'][item] = 'foo' writer = Writer(data, content = '') test_dict = writer.get_current_params() self.assertEqual(test_dict['-t'], data['CL-params']['-t']) self.assertEqual(test_dict['-o'], '~/tmp/out.csv') self.assertEqual(test_dict['-f'], data['CL-params']['-f']) [self.assertEqual(test_dict[item], 'foo') for item in self.mapping]
def test_get_multi_configs2(self): writer = Writer(self.data, content='') config = writer.get_multi_configs(['a16e0bb', '5fa34fc', '01bc2b2', '4a5af86', '5030820', '54af3bd', '8b83879']) self.assertEqual(config, expanduser('~/tmp/config.tar.gz')) tar = tarfile.open(expanduser(config)) tar.extractall(path=expanduser('./config')) tar.close() os.chdir('./config') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1)
def test_get_multi_configs(self): writer = Writer(self.data, content='') config = writer.get_multi_configs([None]) self.assertEqual(config, expanduser('~/tmp/config.tar.gz')) tar = tarfile.open(expanduser(config)) tar.extractall(path=expanduser('./config')) tar.close() os.chdir('./config') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1) param = os.listdir('.')[0] self.assertEqual(param, 'cloud-config-1.xml')
def test_get_parameters5(self): data = json.loads(self.data) writer = Writer(data, content = '') writer.num = 3 test_params = writer.get_parameters([None]) self.assertEqual(test_params, expanduser('~/tmp/params.tar.gz')) tar = tarfile.open(expanduser(test_params)) tar.extractall(path=expanduser('./test-param')) tar.close() os.chdir('./test-param') files = os.listdir('.') self.assertItemsEqual(files, ['cl-params-1.txt','cl-params-2.txt','cl-params-3.txt'])
def test_generate_input5(self): writer = Writer(self.data, content='random') config, param = writer.generate_input([['a16e0bb', '5fa34fc', '01bc2b2', '4a5af86', '5030820', '54af3bd', '8b83879'],['foo','bar','baz']]) self.assertEqual(config, expanduser('~/tmp/config.tar.gz')) tar = tarfile.open(expanduser(config)) tar.extractall(path=expanduser('./config')) tar.close() os.chdir('./config') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 7) self.assertEqual(param, expanduser('~/tmp/params.tar.gz')) tar = tarfile.open(expanduser(param)) tar.extractall(path=expanduser('./test-param')) tar.close() os.chdir('./test-param') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 7)
def test_generate_input3(self): writer = Writer(self.data, content='') config, param = writer.generate_input([[None],['foo','bar','baz']]) self.assertEqual(config, expanduser('~/tmp/config.tar.gz')) tar = tarfile.open(expanduser(config)) tar.extractall(path=expanduser('./config')) tar.close() os.chdir('./config') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1) self.assertEqual(param, expanduser('~/tmp/params.tar.gz')) tar = tarfile.open(expanduser(param)) tar.extractall(path=expanduser('./test-param')) tar.close() os.chdir('./test-param') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1) self.assertEqual(os.listdir('.')[0], 'cl-params-1.txt')
def test_config2(self): writer = Writer(self.data, content='') writer.get_version_config(['2.4', '3.4','5.0']) num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1) config = os.listdir('.')[0] self.assertEqual(config, 'cloud-config-1.xml') tree = ET.parse(config) testTree = ET.parse(self.data['CL-params']['-f']) self.assertNotEqual(tree, testTree) root = tree.getroot() jmh = root.find('.//project/jmh_root').attrib['dir'] self.assertEqual(expanduser(jmh), '/home/selin/tmp/project/benchmarks') versions = [] for item in root.iter(): if item.tag == 'version': versions.append(item.text) self.assertEquals(versions, ['2.4', '3.4','5.0'])
def test_get_parameters4(self): data = json.loads(self.data) writer = Writer(data, content = '') test_params = writer.get_parameters(['foo','bar','baz']) self.assertEqual(test_params, expanduser('~/tmp/params.tar.gz')) tar = tarfile.open(expanduser(test_params)) tar.extractall(path=expanduser('./test-param')) tar.close() os.chdir('./test-param') num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1) param = os.listdir('.')[0] self.assertEqual(param, 'cl-params-1.txt') with open(param, 'r') as f: buf = f.read() self.assertIn("--tests 'foo$|bar$|baz$'", buf) self.assertIn('-o ~/tmp/out.csv', buf) self.assertIn('-f ~/tmp/config/cloud-config-1.xml', buf) self.assertIn('--cloud ~/storage-credentials.json clopper-storage', buf)
def test_config2(self): writer = Writer(self.data, content='') writer.get_config(['a16e0bb', '5fa34fc', '01bc2b2', '4a5af86', '5030820', '54af3bd', '8b83879'],1) num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1) config = os.listdir('.')[0] self.assertEqual(config, 'cloud-config-1.xml') tree = ET.parse(config) testTree = ET.parse(self.data['CL-params']['-f']) self.assertNotEqual(tree, testTree) root = tree.getroot() dir = root.find('.//project').attrib['dir'] self.assertEqual(expanduser(dir), '/home/selin/tmp/project/protostuff') jmh = root.find('.//project/jmh_root').attrib['dir'] self.assertEqual(expanduser(jmh), '/home/selin/tmp/project/benchmarks') v1 = root.find('.//project/versions/start').text v2 = root.find('.//project/versions/end').text self.assertIn(v1, 'a16e0bb') self.assertIn(v2, '8b83879')
def test_config(self): writer = Writer(self.data, content='') writer.get_config([None],1) num_files = len([name for name in os.listdir('.')]) self.assertEquals(num_files, 1) config = os.listdir('.')[0] self.assertEqual(config, 'cloud-config-1.xml') tree = ET.parse(config) testTree = ET.parse(self.data['CL-params']['-f']) self.assertNotEqual(tree, testTree) root = tree.getroot() dir = root.find('.//project').attrib['dir'] self.assertEqual(expanduser(dir), '/home/selin/tmp/project/protostuff') jmh = root.find('.//project/jmh_root').attrib['dir'] self.assertEqual(expanduser(jmh), '/home/selin/tmp/project/benchmarks') v1 = root.find('.//project/versions/start').text v2 = root.find('.//project/versions/end').text self.assertIn(v1, '8924a5f') self.assertIn(v2, '4c2ec16') self.assertEqual(self.data['CL-params']['-f'],"/home/selin/Documents/Uni/Bachelorthesis/Testing/test-conf.xml")
def start_execution(options): f = open(options.file, 'r') content = f.read() read_content = ReadContents() instructions = Instructions() #print "Id 2 :", id(instructions) registers = Registers() memory = Memory() read_content.read_iregisters(content) read_content.read_fpregisters(content) read_content.read_memory(content) read_content.get_instructions(content) #instructions, registers, memory = read_content.return_attrs() instructions = read_content.return_attrs() #print "registers: ", id(registers), " Inst : ", id(instructions.registers), id(memory), id(instructions.memory) #print instructions.get_instructions(), '\n', registers.r['R2'], '\n', memory.location, '\n', registers.f instructions.build_instruction_objects() #print instructions.instructions_object_list #print "In main file : ", id(memory), id(registers), id(instructions) clock = Clock(instructions) #clock.print_object_ids() #print clock.start_clock() #print clock.clock clock.next_instruction() #print "log : ", Registers.f['F4']['contents'] writer = Writer(clock.clock_execution_dict, Registers.f, len(instructions.instructions_object_list)) writer.write_to_file() writer.write_to_file_registers()
def test_eval_input(self): data = json.loads(self.data) writer = Writer(data, content = 'random') answer = writer.eval_input() self.assertTrue(answer) writer = Writer(data, content = '') answer = writer.eval_input() self.assertFalse(answer)
def main(): global oscComunication, logging_manager, dataSources, power, audio, writer print("---------------------------------------------") print("Starting Program [{}]".format(datetime.now().strftime("%m/%d/%Y, %H:%M:%S"))) print("---------------------------------------------") config = GetConfig(config_path) for key, value in config.items(): print("{}\t\t{}".format(key, value)) print("---------------------------------------------") writer = Writer(data_path, config) power = Power() ## Setup OSC oscComunication = OSCComunication(config["IP"]) asyncio.ensure_future( oscComunication.start_server() ) ## Setup Data Sources dataSources = [ AdcDataSource(), PolarDataSource(config["PolarMAC"]) ] audio = AudioRecorder(writer) ## Setup Logging logging_manager = LoggingManager(writer) for dataSource in dataSources: logging_manager.add_logging_channel(dataSource.name) loop = asyncio.get_event_loop() asyncio.ensure_future(main_loop()) asyncio.ensure_future(audio.main_loop()) asyncio.ensure_future(oscComunication.main_loop()) for dataSource in dataSources: dataSource.start() loop.run_forever() print("---------------------------------------------") print("Ending Program [{}]".format(datetime.now().strftime("%m/%d/%Y, %H:%M:%S"))) print("---------------------------------------------")