def test_assyfile_to_cs_basic_ops(self): this_function_name = sys._getframe().f_code.co_name staged = self.staged['assy_file'] dest_ws = self.create_random_workspace(this_function_name) dest_obj_name = 'foo2' args = {'source_kbase_type': staged['obj_info'][2].split('-')[0], 'destination_kbase_type': 'KBaseGenomes.ContigSet', 'source_workspace_name': staged['obj_info'][7], 'destination_workspace_name': dest_ws, 'source_object_name': staged['obj_info'][1], 'destination_object_name': dest_obj_name, 'workspace_service_url': self.ws_url, 'ujs_service_url': self.ujs_url, 'working_directory': dest_ws} expect_err = 'INFO - Conversion completed.' self.run_and_check('convert', args, None, expect_err, not_expect_err='ERROR') newobj = self.ws.get_objects([{'workspace': dest_ws, 'name': dest_obj_name}])[0] prov = newobj['provenance'][0] ref = staged['ref'] assert prov['input_ws_objects'] == [ref] assert prov['resolved_ws_objects'] == [ref] assert prov['script'] ==\ 'trns_transform_KBaseFile_AssemblyFile_to_KBaseGenomes_ContigSet' assert prov['script_ver'] == '0.0.1' with open(os.path.join(FILE_LOC, 'test_files/ContigSetOut.json')) as f: expected = json.loads(f.read()) expected['fasta_ref'] = staged['node'] deep_eq(expected, newobj['data'], _assert=True)
def test_assyfile_to_cs_basic_ops(self): print('*** running test test_assyfile_to_cs_basic _ops ***') staged = self.staged['assy_file'] ref = staged['ref'] bc = BaseClient(self.callbackURL) bc.call_method('CallbackServer.set_provenance', [{'service': 'myserv', 'method': 'mymeth', 'service_ver': '0.0.2', 'method_params': ['foo', 'bar', 'baz'], 'input_ws_objects': [ref] }] ) ret = self.getImpl().convert( self.ctx, {'workspace_name': self.getWsName(), 'assembly_file': staged['obj_info'][1], 'output_name': 'foobarbaz' })[0] report = self.wsClient.get_objects([{'ref': ret['report_ref']}])[0] self.assertEqual('KBaseReport.Report', report['info'][2].split('-')[0]) self.assertEqual(1, len(report['data']['objects_created'])) self.assertEqual('Assembled contigs', report['data']['objects_created'][0]['description']) self.assertIn('Assembled into 4 contigs', report['data']['text_message']) cs_ref = report['data']['objects_created'][0]['ref'] cs = self.wsClient.get_objects([{'ref': cs_ref}])[0] self.assertEqual('KBaseGenomes.ContigSet', cs['info'][2].split('-')[0]) rep_prov = report['provenance'] cs_prov = cs['provenance'] self.assertEqual(len(rep_prov), 1) self.assertEqual(len(cs_prov), 1) rep_prov = rep_prov[0] cs_prov = cs_prov[0] for p in [rep_prov, cs_prov]: self.assertEqual(p['service'], 'myserv') self.assertEqual(p['method'], 'mymeth') self.assertEqual(p['service_ver'], '0.0.2') self.assertEqual(p['method_params'], ['foo', 'bar', 'baz']) self.assertEqual(p['input_ws_objects'], [ref]) self.assertEqual(p['resolved_ws_objects'], [ref]) sa = p['subactions'] self.assertEqual(len(sa), 0) # don't check ver or commit since they can change from run to run with open(os.path.join(FILE_LOC, 'ContigSetOut.json')) as f: expected = json.loads(f.read()) expected['fasta_ref'] = staged['node'] deep_eq(expected, cs['data'], _assert=True)
def test(): print "TESTING ObjWriter..." writer = ObjWriter() blob = "aa" c = writer.make_blob_(blob) assert (c == "blob 2\naa") (s, v) = writer.parse_blob_(c) assert (s == 9) deep_eq(v, blob, _assert=True) assert (writer.digest_content("blob 2\naa") == "e3b380d24c97baeca9843158f63c876d05492caf") assert (writer.digest_obj("aa") == "e3b380d24c97baeca9843158f63c876d05492caf") clst = ["aa", "", "bb"] c = writer.make_clst_(clst) assert (c == "clst 28\n" "blob 2\naa\n" "blob 0\n\n" "blob 2\nbb\n") (s, v) = writer.parse_clst_(c) assert (s == 36) deep_eq(v, clst, _assert=True) cmap = {"a": "aa", "": "", "b": "bb"} c = writer.make_cmap_(cmap) assert (c == "cmap 33\n" "\nblob 0\n\n" "a\nblob 2\naa\n" "b\nblob 2\nbb\n") (s, v) = writer.parse_cmap_(c) assert (s == 41) deep_eq(v, cmap, _assert=True) obj = {'cmap': cmap, 'clst': clst, 'blob': blob} c = writer.make_obj(obj) (s, v) = writer.parse_obj(c) deep_eq(v, obj, _assert=True) print "SUCCESS ObjWriter" return True
def test(): """ Unitary test, returns True if passed. """ class TestNameSpace(NameSpace): def opt_X(self, args): self.X_kind = args[0][2:] self.X_arg = args[1] print "TESTING: GenArgumentParser..." parser = GenArgumentParser() ns, args = parser.parse_args(shlex.split("-E -oout.i file.c file2.cc")) parser = GenArgumentParser() parser.add_argument("-E") parser.add_argument("-c") parser.add_argument("-S") parser.add_argument("-W") parser.add_argument("-Wall") parser.add_argument("-o", nargs=1, dest="output") parser.add_argument("-mtune", nargs=1, sep="=", dest="tune") parser.add_argument("--help", nargs=1, optsep="=", dest="help") parser.add_argument(re="-X.*", nargs=1, next=True, dest="opt_X") parser.add_argument(re="-f(no-)?inline") parser.add_argument(re="-m.*") parser.add_argument(re="-W.*") parser.add_argument(re="-f.*") ns, args = parser.parse_args(shlex.split("-E -oout.i file.c file2.cc")) deep_eq( args, [["-E"], ["-o", "out.i"], [None, "file.c"], [None, "file2.cc"]], _assert=True) deep_eq(vars(ns), { 'output': 'out.i', 'REMAINDER': ['file.c', 'file2.cc'] }, _assert=True) ns, args = parser.parse_args( shlex.split( "-o out.o -c -finline -fno-inline -W -Wall " "file.c -Wother -mtune=i586 --help=warnings --help driver " "-Xpreprocessed afile -undef"), TestNameSpace()) deep_eq( args, [["-o", "out.o"], ["-c"], ["-finline"], ["-fno-inline"], ["-W"], ["-Wall"], [None, "file.c"], ["-Wother"], ["-mtune", "i586"], ["--help", "warnings"], ["--help", "driver"], ["-Xpreprocessed", "afile"], [None, "-undef"]], _assert=True) deep_eq(vars(ns), { 'help': 'driver', 'tune': 'i586', 'X_kind': 'preprocessed', 'X_arg': 'afile', 'output': 'out.o', 'REMAINDER': ['file.c', '-undef'] }, _assert=True) try: args = None _, args = parser.parse_args(shlex.split("-o")) except MalformedArgument, e: pass
def test(): """ Unitary test, returns True if passed. """ class TestNameSpace(NameSpace): def opt_X(self, args): self.X_kind = args[0][2:] self.X_arg = args[1] print "TESTING: GenArgumentParser..." parser = GenArgumentParser() ns, args = parser.parse_args(shlex.split( "-E -oout.i file.c file2.cc")) parser = GenArgumentParser() parser.add_argument("-E") parser.add_argument("-c") parser.add_argument("-S") parser.add_argument("-W") parser.add_argument("-Wall") parser.add_argument("-o", nargs=1, dest="output") parser.add_argument("-mtune", nargs=1, sep="=", dest="tune") parser.add_argument("--help", nargs=1, optsep="=", dest="help") parser.add_argument(re="-X.*", nargs=1, next=True, dest="opt_X") parser.add_argument(re="-f(no-)?inline") parser.add_argument(re="-m.*") parser.add_argument(re="-W.*") parser.add_argument(re="-f.*") ns, args = parser.parse_args(shlex.split( "-E -oout.i file.c file2.cc")) deep_eq(args, [["-E"], ["-o", "out.i"], [None, "file.c"], [None, "file2.cc"]], _assert=True) deep_eq(vars(ns), {'output': 'out.i', 'REMAINDER': ['file.c', 'file2.cc']}, _assert=True) ns, args = parser.parse_args(shlex.split( "-o out.o -c -finline -fno-inline -W -Wall " "file.c -Wother -mtune=i586 --help=warnings --help driver " "-Xpreprocessed afile -undef"), TestNameSpace()) deep_eq(args, [["-o", "out.o"], ["-c"], ["-finline"], ["-fno-inline"], ["-W"], ["-Wall"], [None, "file.c"], ["-Wother"], ["-mtune", "i586"], ["--help", "warnings"], ["--help", "driver"], ["-Xpreprocessed", "afile"], [None, "-undef"]], _assert=True) deep_eq(vars(ns), {'help': 'driver', 'tune': 'i586', 'X_kind': 'preprocessed', 'X_arg': 'afile', 'output': 'out.o', 'REMAINDER': ['file.c', '-undef']}, _assert=True) try: args = None _, args = parser.parse_args(shlex.split("-o")) except MalformedArgument, e: pass
def test_assyfile_to_cs_basic_ops(self): this_function_name = sys._getframe().f_code.co_name staged = self.staged['assy_file'] dest_ws = self.create_random_workspace(this_function_name) dest_obj_name = 'foo2' args = { 'source_kbase_type': staged['obj_info'][2].split('-')[0], 'destination_kbase_type': 'KBaseGenomes.ContigSet', 'source_workspace_name': staged['obj_info'][7], 'destination_workspace_name': dest_ws, 'source_object_name': staged['obj_info'][1], 'destination_object_name': dest_obj_name, 'workspace_service_url': self.ws_url, 'ujs_service_url': self.ujs_url, 'working_directory': dest_ws } expect_err = 'INFO - Conversion completed.' self.run_and_check('convert', args, None, expect_err, not_expect_err='ERROR') newobj = self.ws.get_objects([{ 'workspace': dest_ws, 'name': dest_obj_name }])[0] prov = newobj['provenance'][0] ref = staged['ref'] assert prov['input_ws_objects'] == [ref] assert prov['resolved_ws_objects'] == [ref] assert prov['script'] ==\ 'trns_transform_KBaseFile_AssemblyFile_to_KBaseGenomes_ContigSet' assert prov['script_ver'] == '0.0.1' with open(os.path.join(FILE_LOC, 'test_files/ContigSetOut.json')) as f: expected = json.loads(f.read()) expected['fasta_ref'] = staged['node'] deep_eq(expected, newobj['data'], _assert=True)
def test_sh_src_switch_get_raw_sets(self, shfilename, expected_sets): self.reader = sh_switch.SwitchReader(shfilename) raw_sets = self.reader.get_raw_sets() for switch in raw_sets: idx = 0 for idx, exp_switch in enumerate(expected_sets): if deep_eq.deep_eq(switch, exp_switch): del expected_sets[idx] idx = 0 break if idx: self.fail("Unexpected raw set: %r" % switch)
def test(): print "TESTING: LDInterpreter..." ld = LDInterpreter( {'args': shlex.split("ld a.o b.o c.c d.ro e.os f.a"), 'cwd': "."}) assert(ld.ccld_interpreter() != None) deep_eq(ld.get_kind(), "LD", _assert=True) deep_eq(ld.get_output_files(), ["a.out"], _assert=True) # test cache (self.output_files_) deep_eq(ld.get_output_files(), ["a.out"], _assert=True) deep_eq(ld.get_input_pairs(), [('SRC_LNK', "a.o"), ('SRC_LNK', "b.o"), ('SRC_LNK', "c.c"), ('SRC_LNK', "d.ro"), ('SRC_LNK', "e.os"), ('SRC_LNK', "f.a")], _assert=True) deep_eq(ld.get_input_files(), ["a.o", "b.o", "c.c", "d.ro", "e.os", "f.a"], _assert=True) ld = LDInterpreter( {'args': shlex.split("ld -o"), 'cwd': "."}) assert(ld.is_wellformed() == False) assert(ld.get_args() == ['ld', '-o']) print "SUCCESS: LDInterpreter" return True
def test(): print "TESTING: LDInterpreter..." ld = LDInterpreter({ 'args': shlex.split("ld a.o b.o c.c d.ro e.os f.a"), 'cwd': "." }) assert (ld.ccld_interpreter() != None) deep_eq(ld.get_kind(), "LD", _assert=True) deep_eq(ld.get_output_files(), ["a.out"], _assert=True) # test cache (self.output_files_) deep_eq(ld.get_output_files(), ["a.out"], _assert=True) deep_eq(ld.get_input_pairs(), [('SRC_LNK', "a.o"), ('SRC_LNK', "b.o"), ('SRC_LNK', "c.c"), ('SRC_LNK', "d.ro"), ('SRC_LNK', "e.os"), ('SRC_LNK', "f.a")], _assert=True) deep_eq(ld.get_input_files(), ["a.o", "b.o", "c.c", "d.ro", "e.os", "f.a"], _assert=True) ld = LDInterpreter({'args': shlex.split("ld -o"), 'cwd': "."}) assert (ld.is_wellformed() == False) assert (ld.get_args() == ['ld', '-o']) print "SUCCESS: LDInterpreter" return True
def abstract_key_value_parser_init(self, testnr, seed, rootkv, data): """ flat-key-value parser init """ parser = self.Parser(seed=seed, rootkey=rootkv) self.assert_( isinstance( parser.data, type( data ) ), "%i: Got %r instance instead of %r" % ( testnr, type( parser.data ), type( data ) ) ) if rootkv != None: parser.set_kv(rootkv) eq = False try: eq = deep_eq.deep_eq( parser.data, data ) except: pass self.assert_( eq, "%i: %r does not match %r" % ( testnr, parser.data, data ))
def test(): print "TESTING ObjWriter..." writer = ObjWriter() blob = "aa" c = writer.make_blob_(blob) assert(c == "blob 2\naa") (s, v) = writer.parse_blob_(c) assert(s == 9) deep_eq(v, blob, _assert=True) assert(writer.digest_content("blob 2\naa") == "e3b380d24c97baeca9843158f63c876d05492caf") assert(writer.digest_obj("aa") == "e3b380d24c97baeca9843158f63c876d05492caf") clst = ["aa", "", "bb"] c = writer.make_clst_(clst) assert(c == "clst 28\n" "blob 2\naa\n" "blob 0\n\n" "blob 2\nbb\n") (s, v) = writer.parse_clst_(c) assert(s == 36) deep_eq(v, clst, _assert=True) cmap = {"a": "aa", "": "", "b": "bb"} c = writer.make_cmap_(cmap) assert(c == "cmap 33\n" "\nblob 0\n\n" "a\nblob 2\naa\n" "b\nblob 2\nbb\n") (s, v) = writer.parse_cmap_(c) assert(s == 41) deep_eq(v, cmap, _assert=True) obj = {'cmap': cmap, 'clst': clst, 'blob': blob} c = writer.make_obj(obj) (s, v) = writer.parse_obj(c) deep_eq(v, obj, _assert=True) print "SUCCESS ObjWriter" return True
def test(): # pragma: uncovered (ignore test funcs) class TestNameSpace(): pass print "TESTING LDArgumentsParser..." tmpdir = tempfile.mkdtemp() try: parser = LDArgumentParser("ld") ns = parser.parse_args(shlex.split("--help"), TestNameSpace()) deep_eq(ns.unknown_flags, [], _assert=True) deep_eq(ns.outputs, [], _assert=True) deep_eq(ns.inputs, [], _assert=True) deep_eq(ns.output_kind, 'nooutput', _assert=True) interp = LDArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), [], _assert=True) deep_eq(interp.all_cc_inputs(), [], _assert=True) deep_eq(interp.is_ld_kind("program"), False, _assert=True) deep_eq(interp.has_final_link(), False, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) ns = parser.parse_args(shlex.split("--version"), TestNameSpace()) deep_eq(ns.output_kind, 'nooutput', _assert=True) ns = parser.parse_args(shlex.split("-o a.exe in.o"), TestNameSpace()) deep_eq(ns.unknown_flags, [], _assert=True) deep_eq(ns.output_kind, 'executable', _assert=True) deep_eq(ns.outputs, ["a.exe"], _assert=True) deep_eq(ns.inputs, ["in.o"], _assert=True) interp = LDArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), ["a.exe"], _assert=True) deep_eq(interp.all_cc_inputs(), ["in.o"], _assert=True) deep_eq(interp.is_ld_kind("program"), True, _assert=True) deep_eq(interp.has_final_link(), True, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) with open("%s/libc.so" % tmpdir, 'w') as f: print >> f, "// A shared object" with open("%s/libd.a" % tmpdir, 'w') as f: print >> f, "// A static archive" ns = parser.parse_args( shlex.split( ("-o out --build-id -r in.o -L%s -( -la -lb -) " + "-Bdynamic -lc -Bstatic -ld " + "-aarchive -le -ashared -lf -adefault -lg -a unknown") % (tmpdir)), TestNameSpace()) deep_eq(ns.unknown_flags, [], _assert=True) deep_eq(ns.output_kind, 'relocatable', _assert=True) deep_eq(ns.outputs, ["out"], _assert=True) deep_eq( ns.inputs, ["in.o", "%s/libc.so" % tmpdir, "%s/libd.a" % tmpdir], _assert=True) interp = LDArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), ["out"], _assert=True) deep_eq( interp.all_cc_inputs(), ["in.o", "%s/libc.so" % tmpdir, "%s/libd.a" % tmpdir], _assert=True) deep_eq(interp.is_ld_kind("relocatable"), True, _assert=True) deep_eq(interp.has_final_link(), False, _assert=True) deep_eq(interp.has_reloc_link(), True, _assert=True) ns = parser.parse_args(shlex.split("-o out in.o --notanoption"), TestNameSpace()) interp = LDArgumentInterpreter(ns) deep_eq(ns.unknown_flags, ["--notanoption"], _assert=True) finally: shutil.rmtree(tmpdir) print "SUCCESS LDArgumentsParser" return True
boundary['outlet'] = { 'type':'fixedValue', 'value': 'uniform 10' } with IOField.handle(time): U.write() T.write() with IOField.handle(time): Tn = IOField.read('T') Un = IOField.read('U') Un.partialComplete() config.hdf5 = False assert (deep_eq(Tn.boundary, T.boundary)) assert (deep_eq(Un.boundary, U.boundary)) np.allclose(Tn.field, T.field) np.allclose(Un.field, U.field) @pytest.mark.skip def test_field_io_mpi(case): mesh = Mesh.create(case) Field.setMesh(mesh) time = 1.0 config.hdf5 = False with IOField.handle(time): U = IOField.read('U') U.partialComplete()
def test(): # pragma: uncovered (ignore test funcs) class TestNameSpace(): pass print "TESTING LDArgumentsParser..." tmpdir = tempfile.mkdtemp() try: parser = LDArgumentParser("ld") ns = parser.parse_args(shlex.split( "--help"), TestNameSpace()) deep_eq(ns.unknown_flags, [], _assert=True) deep_eq(ns.outputs, [], _assert=True) deep_eq(ns.inputs, [], _assert=True) deep_eq(ns.output_kind, 'nooutput', _assert=True) interp = LDArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), [], _assert=True) deep_eq(interp.all_cc_inputs(), [], _assert=True) deep_eq(interp.is_ld_kind("program"), False, _assert=True) deep_eq(interp.has_final_link(), False, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) ns = parser.parse_args(shlex.split( "--version"), TestNameSpace()) deep_eq(ns.output_kind, 'nooutput', _assert=True) ns = parser.parse_args(shlex.split( "-o a.exe in.o"), TestNameSpace()) deep_eq(ns.unknown_flags, [], _assert=True) deep_eq(ns.output_kind, 'executable', _assert=True) deep_eq(ns.outputs, ["a.exe"], _assert=True) deep_eq(ns.inputs, ["in.o"], _assert=True) interp = LDArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), ["a.exe"], _assert=True) deep_eq(interp.all_cc_inputs(), ["in.o"], _assert=True) deep_eq(interp.is_ld_kind("program"), True, _assert=True) deep_eq(interp.has_final_link(), True, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) with open("%s/libc.so" % tmpdir, 'w') as f: print >>f, "// A shared object" with open("%s/libd.a" % tmpdir, 'w') as f: print >>f, "// A static archive" ns = parser.parse_args(shlex.split( ("-o out --build-id -r in.o -L%s -( -la -lb -) " + "-Bdynamic -lc -Bstatic -ld " + "-aarchive -le -ashared -lf -adefault -lg -a unknown") % (tmpdir)), TestNameSpace()) deep_eq(ns.unknown_flags, [], _assert=True) deep_eq(ns.output_kind, 'relocatable', _assert=True) deep_eq(ns.outputs, ["out"], _assert=True) deep_eq(ns.inputs, ["in.o", "%s/libc.so" % tmpdir, "%s/libd.a" % tmpdir], _assert=True) interp = LDArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), ["out"], _assert=True) deep_eq(interp.all_cc_inputs(), ["in.o", "%s/libc.so" % tmpdir, "%s/libd.a" % tmpdir], _assert=True) deep_eq(interp.is_ld_kind("relocatable"), True, _assert=True) deep_eq(interp.has_final_link(), False, _assert=True) deep_eq(interp.has_reloc_link(), True, _assert=True) ns = parser.parse_args(shlex.split( "-o out in.o --notanoption"), TestNameSpace()) interp = LDArgumentInterpreter(ns) deep_eq(ns.unknown_flags, ["--notanoption"], _assert=True) finally: shutil.rmtree(tmpdir) print "SUCCESS LDArgumentsParser" return True
def test_eq(x, y): res = deep_eq(x, y) if not res: # pragma: uncovered (error) print "FAILURE: %s and %s differ" % (str(x), str(y)) return res
def test_sample_quiz(): """Check that kahoot quiz format is correct for .sample_quiz.quiz.""" user = '******' title = 'Test' #qm = quiztoolsKahootQuizMaker.KahootQuizMaker( qm = KahootQuizMaker.KahootQuizMaker(user, path='', loglvl=logging.DEBUG, login=False) filename = '.sample_quiz.quiz' questions = qm.read_quiz_file(filename) computed = qm.make_quiz(questions, title=title) #pprint.pprint(computed) expected = { 'audience': 'University', 'description': 'Made using quiztools.', 'difficulty': 500, 'language': 'English', 'questions': [{ 'choices': [{ 'answer': 'a)', 'correct': True }, { 'answer': 'b)', 'correct': True }, { 'answer': 'c)', 'correct': False }, { 'answer': 'd)', 'correct': True }], 'iframe': { 'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>Which of the following cities are capitals?</p><hr><p class='answer'><span class='letter'>a)</span> Bern</p><hr><p class='answer'><span class='letter'>b)</span> Kigali</p><hr><p class='answer'><span class='letter'>c)</span> New York</p><hr><p class='answer'><span class='letter'>d)</span> Ottawa</p></body></html>" }, 'image': '', 'numberOfAnswers': 4, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': { 'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0 } }, { 'choices': [{ 'answer': 'a)', 'correct': False }, { 'answer': 'b)', 'correct': False }, { 'answer': 'c)', 'correct': False }, { 'answer': 'd)', 'correct': True }], 'iframe': { 'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>What is the capital of Norway?</p><hr><p class='answer'><span class='letter'>a)</span> Helsinki</p><hr><p class='answer'><span class='letter'>b)</span> Denmark</p><hr><p class='answer'><span class='letter'>c)</span> Drammen</p><hr><p class='answer'><span class='letter'>d)</span> Oslo</p></body></html>" }, 'image': '', 'numberOfAnswers': 4, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': { 'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0 } }, { 'choices': [{ 'answer': 'a)', 'correct': True }, { 'answer': 'b)', 'correct': False }, { 'answer': 'c)', 'correct': False }], 'iframe': { 'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>This is a very famous quote:\n\n<p>\n<blockquote>\n <em>Premature optimization is the root of all evil.</em>\n</blockquote>\n\nThis quote is attributed to</p><hr><p class='answer'><span class='letter'>a)</span> Donald Knuth</p><hr><p class='answer'><span class='letter'>b)</span> Ole-Johan Dahl</p><hr><p class='answer'><span class='letter'>c)</span> George W. Bush</p></body></html>" }, 'image': '', 'numberOfAnswers': 3, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': { 'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0 } }, { 'choices': [{ 'answer': 'a)', 'correct': False }, { 'answer': 'b)', 'correct': False }, { 'answer': 'c)', 'correct': True }], 'iframe': { 'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>Compute the result of \\( a+b \\) in the case \\( a=2 \\) and \\( b=2 \\).</p><hr><p class='answer'><span class='letter'>a)</span> 5.</p><hr><p class='answer'><span class='letter'>b)</span> The computation does not make sense when \\( a \\) and \\( b \\) are given without\nunits.</p><hr><p class='answer'><span class='letter'>c)</span> 4.</p></body></html>" }, 'image': '', 'numberOfAnswers': 3, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': { 'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0 } }, { 'choices': [{ 'answer': 'a)', 'correct': False }, { 'answer': 'b)', 'correct': False }, { 'answer': 'c)', 'correct': True }, { 'answer': 'd)', 'correct': True }], 'iframe': { 'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>The equation\n\n$$\n\\begin{equation}\n\\nabla\\cdot\\boldsymbol{u} = 0\n\\label{cont:eq}\n\\end{equation}\n$$\n\nis famous in physics. Select the wrong assertion(s):</p><hr><p class='answer'><span class='letter'>a)</span> The equation tells that the vector field \\( \\boldsymbol{u} \\) is divergence free.</p><hr><p class='answer'><span class='letter'>b)</span> The equation implies that there exists a vector potential \\( \\boldsymbol{A} \\)\nsuch that \\( \\boldsymbol{u}=\\nabla\\times\\boldsymbol{A} \\).</p><hr><p class='answer'><span class='letter'>c)</span> The equation implies \\( \\nabla\\times\\boldsymbol{u}=0 \\).</p><hr><p class='answer'><span class='letter'>d)</span> The equation implies that \\( \\boldsymbol{u} \\) must be a constant vector field.</p></body></html>" }, 'image': '', 'keywords': ['gradient', 'divergence', 'curl', 'vector calculus'], 'numberOfAnswers': 4, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': { 'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0 } }, { 'choices': [{ 'answer': 'a)', 'correct': True }, { 'answer': 'b)', 'correct': False }, { 'answer': 'c)', 'correct': False }], 'iframe': { 'content': u'<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type=\'text/javascript\' src=\'//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\'></script></head><body><p class=\'question\'>We want to create a Python list object of length <code>n</code> where each\nelement is <code>0</code>. Is the following code then what we need?\n\n<p>\n\n<!-- code=python (!bc pycod) typeset with pygments style "default" -->\n<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span>\nmylist <span style="color: #666666">=</span> numpy<span style="color: #666666">.</span>zeros(n)\n</pre></div>\n<p></p><hr><p class=\'answer\'><span class=\'letter\'>a)</span> No.</p><hr><p class=\'answer\'><span class=\'letter\'>b)</span> Yes.</p><hr><p class=\'answer\'><span class=\'letter\'>c)</span> Yes, provided we write <code>np</code> instead of <code>numpy</code>:\n\n<p>\n\n<!-- code=python (!bc pycod) typeset with pygments style "default" -->\n<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>\nmylist <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(n)\n</pre></div>\n<p></p></body></html>' }, 'image': '', 'numberOfAnswers': 3, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': { 'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0 } }, { 'choices': [{ 'answer': 'a)', 'correct': False }, { 'answer': 'b)', 'correct': False }, { 'answer': 'c)', 'correct': False }, { 'answer': 'd)', 'correct': True }], 'iframe': { 'content': u'<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type=\'text/javascript\' src=\'//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\'></script></head><body><p class=\'question\'><p>\n\n<!-- code=python (!bc pypro) typeset with pygments style "default" -->\n<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">math</span> <span style="color: #008000; font-weight: bold">import</span> sin\n\n<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">D</span>(u, t, dt<span style="color: #666666">=1E-5</span>):\n <span style="color: #008000; font-weight: bold">return</span> (u(t <span style="color: #666666">+</span> dt) <span style="color: #666666">-</span> u(t <span style="color: #666666">-</span> dt))<span style="color: #666666">/</span>(<span style="color: #666666">2*</span>dt)\n\n<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">u</span>(t):\n <span style="color: #BA2121">"A quadratic function."</span>\n <span style="color: #008000; font-weight: bold">return</span> t<span style="color: #666666">^2</span>\n\n<span style="color: #008000; font-weight: bold">print</span> D(u, t<span style="color: #666666">=4</span>),\n<span style="color: #008000; font-weight: bold">print</span> D(<span style="color: #008000; font-weight: bold">lambda</span> x: <span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">2*</span>x, <span style="color: #666666">2</span>)\n</pre></div>\n<p>\nThe purpose of this program is to differentiate the two mathematical\nfunctions\n\n$$\n\\begin{align*}\nu(t) &= t^2,\\\\\nf(x) &= 2x.\n\\end{align*}\n$$\n\nDetermine which of the following assertions that is <b>wrong</b>.</p><hr><p class=\'answer\'><span class=\'letter\'>a)</span> The <code>D</code> function computes an approximate derivative of the\nfunction <code>u(t)</code>.</p><hr><p class=\'answer\'><span class=\'letter\'>b)</span> The call <code>D(lambda x: return 2*x, 2)</code> is equivalent to defining\n\n<p>\n\n<!-- code=python (!bc pycod) typeset with pygments style "default" -->\n<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">f</span>(x):\n <span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">2*</span>x\n</pre></div>\n<p>\nand then calling <code>D(f, 2)</code>.</p><hr><p class=\'answer\'><span class=\'letter\'>c)</span> The string in the <code>u</code> function is a valid doc string.</p><hr><p class=\'answer\'><span class=\'letter\'>d)</span> One cannot use <code>u</code> both inside the <code>D</code> function and in the\nouter calling code (the main program).</p></body></html>' }, 'image': '', 'numberOfAnswers': 4, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': { 'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0 } }], 'quizType': 'quiz', 'title': 'Test', 'type': 'quiz', 'visibility': 0 } from deep_eq import deep_eq success = deep_eq(expected, computed) #print success assert success
def test(): print "TESTING: ARInterpreter..." ar = ARInterpreter({ 'args': shlex.split("ar cru lib.a a.o b.o c.c"), 'cwd': "." }) assert (ar.is_wellformed() == True) deep_eq(ar.get_kind(), "AR", _assert=True) deep_eq(ar.get_output_files(), ["lib.a"], _assert=True) deep_eq(ar.get_output_files(), ["lib.a"], _assert=True) deep_eq(ar.get_input_pairs(), [('SRC_AR', "a.o"), ('SRC_AR', "b.o"), ('SRC_AR', "c.c")], _assert=True) deep_eq(ar.get_input_files(), ["a.o", "b.o", "c.c"], _assert=True) ar = ARInterpreter({'args': shlex.split("ar -v"), 'cwd': "."}) deep_eq(ar.get_output_files(), [], _assert=True) print "SUCCESS: ARInterpreter" return True
def test(): # pragma: uncovered (ignore test funcs) print "TESTING RecipeManager..." tmpdir = tempfile.mkdtemp() try: stgdir = os.path.join(tmpdir, "stg") stg = RecipeStorage(stgdir) stg.init_recipes_file() with open(os.path.join(tmpdir, "a.c"), "w") as f: f.write("int main() { return foo(); }\n") with open(os.path.join(tmpdir, "b.c"), "w") as f: f.write("int foo() { return 0; }\n") with open(os.path.join(tmpdir, "c.c"), "w") as f: f.write("int foo() { return 1; }\n") prog = "/usr/bin/gcc" envs = {'PATH': "/usr/bin:/bin", 'HOME': "/home/undef"} cwd = tmpdir for base in ["a", "b", "c"]: src = "%s.c" % base args = ["gcc", "-c", src] inps_digest = stg.store_path_ref_list([ os.path.join(tmpdir, src)]) cnod_digest = stg.store_cmd_node(prog, cwd, args, envs, "CC") if subprocess.Popen(args, cwd=cwd, env=envs).wait() != 0: return False outs_digest = stg.store_path_ref_list([ os.path.join(tmpdir, "%s.o" % base)]) rnod_digest = stg.store_recipe_node( cnod_digest, inps_digest, outs_digest) print "%s rnod %s" % (base, rnod_digest) stg.append_recipes_file(rnod_digest) cnod = stg.load_obj(cnod_digest) env = stg.load_envs(cnod['envs']) print "env", env recipe_node = RecipeNode(stg, rnod_digest, cwd) recipe_node.fetch_input_files() recipe_node.get_output_files() # commands.unlink(os.path.join(tmpdir, src)) # recipe_node.fetch_input_files() assert not stg.blacklist_recipes() stg.blacklist_init() print "blacklist_path", stg.blacklist_path() stg.blacklist_append(rnod_digest) print "blacklist_recipes", stg.blacklist_recipes() assert stg.blacklist_contains(rnod_digest) for dest, objs in (("main.exe", ("a.o", "b.o")), ("main2.exe", ("a.o", "c.o"))): args = ["gcc", "-o", dest] + list(objs) inps_digest = stg.store_path_ref_list( [os.path.join(tmpdir, x) for x in objs]) cnod_digest = stg.store_cmd_node(prog, cwd, args, envs, "CC") if subprocess.Popen(args, cwd=cwd, env=envs).wait() != 0: return False outs_digest = stg.store_path_ref_list([ os.path.join(tmpdir, dest)]) rnod_digest = stg.store_recipe_node( cnod_digest, inps_digest, outs_digest) print "%s rnod %s" % (dest, rnod_digest) stg.append_recipes_file(rnod_digest) graph = RecipeManager(stg).recipe_graph() # Test compilers (2 times for testing cache) for i in range(2): deep_eq(graph.get_compilers(), ['/usr/bin/gcc'], _assert=True) # Test targets (2 times for testing cache) for i in range(2): deep_eq(graph.get_targets(), map(lambda x: '%s/%s' % (tmpdir, x), ['main.exe', 'main2.exe']), _assert=True) # Test objects (2 times for testing cache) for i in range(2): deep_eq(graph.get_objects(), map(lambda x: '%s/%s' % (tmpdir, x), ['a.o', 'b.o', 'a.o', 'c.o']), _assert=True) deep_eq(graph.get_compilers(), ['/usr/bin/gcc'], _assert=True) mkfile = os.path.join(tmpdir, "Makefile") with open(mkfile, "w") as f: graph.write_makefile(f) with open(mkfile, "r") as f: print f.read() if subprocess.Popen(["make", "-j8"], cwd=cwd, env=envs).wait() != 0: return False finally: shutil.rmtree(tmpdir) print "SUCCESS RecipeManager" return True
def test(): # pragma: uncovered (ignore test funcs) print "TESTING RecipeManager..." tmpdir = tempfile.mkdtemp() try: stgdir = os.path.join(tmpdir, "stg") stg = RecipeStorage(stgdir) stg.init_recipes_file() with open(os.path.join(tmpdir, "a.c"), "w") as f: f.write("int main() { return foo(); }\n") with open(os.path.join(tmpdir, "b.c"), "w") as f: f.write("int foo() { return 0; }\n") with open(os.path.join(tmpdir, "c.c"), "w") as f: f.write("int foo() { return 1; }\n") prog = "/usr/bin/gcc" envs = {'PATH': "/usr/bin:/bin", 'HOME': "/home/undef"} cwd = tmpdir for base in ["a", "b", "c"]: src = "%s.c" % base args = ["gcc", "-c", src] inps_digest = stg.store_path_ref_list( [os.path.join(tmpdir, src)]) cnod_digest = stg.store_cmd_node(prog, cwd, args, envs, "CC") if subprocess.Popen(args, cwd=cwd, env=envs).wait() != 0: return False outs_digest = stg.store_path_ref_list( [os.path.join(tmpdir, "%s.o" % base)]) rnod_digest = stg.store_recipe_node(cnod_digest, inps_digest, outs_digest) print "%s rnod %s" % (base, rnod_digest) stg.append_recipes_file(rnod_digest) cnod = stg.load_obj(cnod_digest) env = stg.load_envs(cnod['envs']) print "env", env recipe_node = RecipeNode(stg, rnod_digest, cwd) recipe_node.fetch_input_files() recipe_node.get_output_files() # commands.unlink(os.path.join(tmpdir, src)) # recipe_node.fetch_input_files() assert not stg.blacklist_recipes() stg.blacklist_init() print "blacklist_path", stg.blacklist_path() stg.blacklist_append(rnod_digest) print "blacklist_recipes", stg.blacklist_recipes() assert stg.blacklist_contains(rnod_digest) for dest, objs in (("main.exe", ("a.o", "b.o")), ("main2.exe", ("a.o", "c.o"))): args = ["gcc", "-o", dest] + list(objs) inps_digest = stg.store_path_ref_list( [os.path.join(tmpdir, x) for x in objs]) cnod_digest = stg.store_cmd_node(prog, cwd, args, envs, "CC") if subprocess.Popen(args, cwd=cwd, env=envs).wait() != 0: return False outs_digest = stg.store_path_ref_list( [os.path.join(tmpdir, dest)]) rnod_digest = stg.store_recipe_node(cnod_digest, inps_digest, outs_digest) print "%s rnod %s" % (dest, rnod_digest) stg.append_recipes_file(rnod_digest) graph = RecipeManager(stg).recipe_graph() # Test compilers (2 times for testing cache) for i in range(2): deep_eq(graph.get_compilers(), ['/usr/bin/gcc'], _assert=True) # Test targets (2 times for testing cache) for i in range(2): deep_eq(graph.get_targets(), map(lambda x: '%s/%s' % (tmpdir, x), ['main.exe', 'main2.exe']), _assert=True) # Test objects (2 times for testing cache) for i in range(2): deep_eq(graph.get_objects(), map(lambda x: '%s/%s' % (tmpdir, x), ['a.o', 'b.o', 'a.o', 'c.o']), _assert=True) deep_eq(graph.get_compilers(), ['/usr/bin/gcc'], _assert=True) mkfile = os.path.join(tmpdir, "Makefile") with open(mkfile, "w") as f: graph.write_makefile(f) with open(mkfile, "r") as f: print f.read() if subprocess.Popen(["make", "-j8"], cwd=cwd, env=envs).wait() != 0: return False finally: shutil.rmtree(tmpdir) print "SUCCESS RecipeManager" return True
def test(): class TestNameSpace(): pass print "TESTING CCArgumentsParser..." parser = CCArgumentParser("gcc") ns = parser.parse_args(shlex.split( "-E in.c"), TestNameSpace()) interp = CCArgumentInterpreter(ns) parser = CCArgumentParser("gcc") ns = parser.parse_args(shlex.split( "-o out.o -c in.c --help -I/path -pthread"), TestNameSpace()) deep_eq(ns.unknown_flags, [], _assert=True) deep_eq(ns.output_kind, 'nooutput', _assert=True) deep_eq(ns.outputs, ["out.o"], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "in.c")], _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), None, _assert=True) deep_eq(interp.has_cc_phase('CC'), False, _assert=True) deep_eq(interp.cc_phase_inputs('CC'), [], _assert=True) deep_eq(interp.all_cc_inputs(), [], _assert=True) deep_eq(interp.all_cc_outputs(), [], _assert=True) deep_eq(interp.is_ld_kind("program"), False, _assert=True) deep_eq(interp.has_final_link(), False, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) ns = parser.parse_args(shlex.split( "-o out.o -c in.c -print-search-dirs"), TestNameSpace()) deep_eq(ns.output_kind, 'nooutput', _assert=True) deep_eq(ns.outputs, ["out.o"], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "in.c")], _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), [], _assert=True) ns = parser.parse_args(shlex.split( "-o out.o -c in.c -dumpversion"), TestNameSpace()) deep_eq(ns.output_kind, 'nooutput', _assert=True) deep_eq(ns.outputs, ["out.o"], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "in.c")], _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), [], _assert=True) ns = parser.parse_args(shlex.split( "-o out.o -c in.c --version"), TestNameSpace()) deep_eq(ns.output_kind, 'nooutput', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), [], _assert=True) ns = parser.parse_args(shlex.split( "-o out -E in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'preprocessed', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), "CPP", _assert=True) deep_eq(interp.all_cc_outputs(), ["out"], _assert=True) deep_eq(interp.all_cc_inputs(), ["in.c"], _assert=True) deep_eq(interp.has_cc_phase("CPP"), True, _assert=True) deep_eq(interp.has_cc_phase("CC"), False, _assert=True) deep_eq(interp.has_cc_phase("LD"), False, _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in.c"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), [], _assert=True) ns = parser.parse_args(shlex.split( "-o out -M in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'dependencies', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), None, _assert=True) deep_eq(interp.all_cc_inputs(), [], _assert=True) deep_eq(interp.all_cc_outputs(), [], _assert=True) ns = parser.parse_args(shlex.split( "-o out -MM in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'dependencies', _assert=True) ns = parser.parse_args(shlex.split( "-o out -c in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'object', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), "AS", _assert=True) deep_eq(interp.all_cc_inputs(), ["in.c"], _assert=True) deep_eq(interp.all_cc_outputs(), ["out"], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in.c"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), [], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), [], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), [], _assert=True) ns = parser.parse_args(shlex.split( "-S in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'assembly', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), "CC", _assert=True) deep_eq(interp.all_cc_inputs(), ["in.c"], _assert=True) deep_eq(interp.all_cc_outputs(), ["in.s"], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in.c"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), [], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), [], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), [], _assert=True) ns = parser.parse_args(shlex.split( "-S in1.c in2.c in3.i in4.ii in5.s in6.o in7.S"), TestNameSpace()) deep_eq(ns.output_kind, 'assembly', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.has_cc_phase("CC"), True, _assert=True) deep_eq(interp.has_cc_phase("CPP"), True, _assert=True) deep_eq(interp.last_cc_phase(), "CC", _assert=True) deep_eq(interp.all_cc_outputs(), ["in1.s", "in2.s", "in3.s", "in4.s"], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in1.c", "in2.c"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), ["in3.i", "in4.ii"], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), [], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), [], _assert=True) ns = parser.parse_args(shlex.split( "-c /a/in1.c ./in2.c in3.i in4.ii in5.s in6.o in7.S"), TestNameSpace()) deep_eq(ns.output_kind, 'object', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.has_cc_phase("AS"), True, _assert=True) deep_eq(interp.has_cc_phase("CC"), True, _assert=True) deep_eq(interp.has_cc_phase("CPP"), True, _assert=True) deep_eq(interp.last_cc_phase(), "AS", _assert=True) deep_eq(interp.all_cc_outputs(), ["in1.o", "in2.o", "in3.o", "in4.o", "in5.o", "in7.o"], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["/a/in1.c", "./in2.c", "in7.S"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), ["in3.i", "in4.ii"], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), ["in5.s"], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), [], _assert=True) ns = parser.parse_args(shlex.split( "-o all.exe in1.c in2.c in3.i in4.ii in5.s in6.o in7.S"), TestNameSpace()) deep_eq(ns.output_kind, "executable", _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("program"), True, _assert=True) deep_eq(interp.has_final_link(), True, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) deep_eq(interp.has_cc_phase("AS"), True, _assert=True) deep_eq(interp.has_cc_phase("CC"), True, _assert=True) deep_eq(interp.has_cc_phase("CPP"), True, _assert=True) deep_eq(interp.has_cc_phase("LD"), True, _assert=True) deep_eq(interp.last_cc_phase(), "LD", _assert=True) deep_eq(interp.all_cc_outputs(), ["all.exe"], _assert=True) deep_eq(interp.cc_phase_input_pairs("CPP"), [('SRC_C', "in1.c"), ('SRC_C', "in2.c"), ('SRC_SPP', "in7.S")], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in1.c", "in2.c", "in7.S"], _assert=True) deep_eq(interp.cc_phase_input_pairs("CC"), [('SRC_I', "in3.i"), ('SRC_II', "in4.ii")], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), ["in3.i", "in4.ii"], _assert=True) deep_eq(interp.cc_phase_input_pairs("AS"), [('SRC_S', "in5.s")], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), ["in5.s"], _assert=True) deep_eq(interp.cc_phase_input_pairs("LD"), [('SRC_LNK', "in6.o")], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), ["in6.o"], _assert=True) ns = parser.parse_args(shlex.split( "-o out -r in.o"), TestNameSpace()) deep_eq(ns.output_kind, 'relocatable', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("relocatable"), True, _assert=True) deep_eq(interp.has_final_link(), False, _assert=True) deep_eq(interp.has_reloc_link(), True, _assert=True) ns = parser.parse_args(shlex.split( "-o out in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'executable', _assert=True) deep_eq(ns.exec_kind, 'program', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("program"), True, _assert=True) ns = parser.parse_args(shlex.split( "-o out -static in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'executable', _assert=True) deep_eq(ns.exec_kind, 'program', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("program"), True, _assert=True) ns = parser.parse_args(shlex.split( "-o out -shared -static in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'executable', _assert=True) deep_eq(ns.exec_kind, 'shared', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("shared"), True, _assert=True) deep_eq(interp.has_final_link(), True, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) ns = parser.parse_args(shlex.split( "-o out.o -c -finline -Wall " "file1.c file2.cpp file3.cpp file4.s " "-Wother -mtune=i586 " "-Xpreprocessor pfile -Wp,-optp " "-Xassembler afile -Wa,-opta " "-Xlinker -optl -Wl,lfile " "-shared -not-an-option"), TestNameSpace()) deep_eq(ns.outputs, ["out.o"], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "file1.c"), ('SRC_CC', "file2.cpp"), ('SRC_CC', "file3.cpp"), ('SRC_S', "file4.s")], _assert=True) deep_eq(ns.preprocessor_flags, ["pfile", "-optp"], _assert=True) deep_eq(ns.assembler_flags, ["afile", "-opta"], _assert=True) deep_eq(ns.linker_flags, ["-optl", "lfile"], _assert=True) deep_eq(ns.output_kind, 'object', _assert=True) deep_eq(ns.exec_kind, 'shared', _assert=True) deep_eq(ns.unknown_flags, ['-not-an-option'], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "file1.c"), ('SRC_CC', "file2.cpp"), ('SRC_CC', "file3.cpp"), ('SRC_S', "file4.s"), ], _assert=True) tmpdir = tempfile.mkdtemp() f = open("%s/liba.a" % tmpdir, 'w') print >>f, "// An archive" f.close() f = open("%s/liba.so" % tmpdir, 'w') print >>f, "// A shared object" f.close() f = open("%s/libb.a" % tmpdir, 'w') print >>f, "// An archive" f.close() f = open("%s/libc.so" % tmpdir, 'w') print >>f, "// A shared object" f.close() f = open("%s/libd.so" % tmpdir, 'w') print >>f, "// An unreadable shared object" f.close() os.chmod("%s/libd.so" % tmpdir, 0000) f = open("%s/libe.a" % tmpdir, 'w') print >>f, "// An unreadable archive" f.close() os.chmod("%s/libe.a" % tmpdir, 0000) f = open("%s/include.gch" % tmpdir, 'w') print >>f, "// An unreadable pre-compiled header" f.close() ns = parser.parse_args(shlex.split( "-o out.so -shared -L. -Lundef -L%s " "file1.c file2.cpp file3.o " "-x c a_c_file b_c_file -x none " ".libs/lib1.so l2.a " "-x cpp-output i_file -x c++cpp-output ii_file " "-include %s/include " "-lundef -la -lb -lc -ld -le" "-shared" % (tmpdir, tmpdir)), TestNameSpace()) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("shared"), True, _assert=True) deep_eq(interp.all_cc_inputs(), ["%s/include.gch" % tmpdir, "file1.c", "file2.cpp", "file3.o", "a_c_file", "b_c_file", ".libs/lib1.so", "l2.a", "i_file", "ii_file"] + map(lambda x: os.path.join(tmpdir, x), ["liba.so", "libb.a", "libc.so"]), _assert=True) deep_eq(interp.cc_phase_input_pairs("CMD"), [('SRC_PCH', "%s/include.gch" % tmpdir)], _assert=True) deep_eq(interp.all_pch_inputs(), ["%s/include.gch" % tmpdir], _assert=True) deep_eq(interp.cc_phase_input_pairs("CPP"), [('SRC_C', "file1.c"), ('SRC_CC', "file2.cpp"), ('SRC_C', "a_c_file"), ('SRC_C', "b_c_file")], _assert=True) deep_eq(interp.cc_phase_input_pairs("CC"), [('SRC_I', "i_file"), ('SRC_II', "ii_file")], _assert=True) deep_eq(interp.cc_phase_input_pairs("LD"), [('SRC_LNK', "file3.o"), ('SRC_LNK', ".libs/lib1.so"), ('SRC_LNK', "l2.a")] + map(lambda x: ('SRC_LNK', os.path.join(tmpdir, x)), ["liba.so", "libb.a", "libc.so"]), _assert=True) ns = parser.parse_args(shlex.split( "-o out.o -c in.c " "-include %s/include-unk" % (tmpdir)), TestNameSpace()) interp = CCArgumentInterpreter(ns) shutil.rmtree(tmpdir) print "SUCCESS CCArgumentsParser" return True
def test_sample_quiz(): """Check that kahoot quiz format is correct for .sample_quiz.quiz.""" user = '******' title = 'Test' #qm = quiztoolsKahootQuizMaker.KahootQuizMaker( qm = KahootQuizMaker.KahootQuizMaker( user, path='', loglvl=logging.DEBUG, login=False) filename = '.sample_quiz.quiz' questions = qm.read_quiz_file(filename) computed = qm.make_quiz(questions, title=title) #pprint.pprint(computed) expected = { 'audience': 'University', 'description': 'Made using quiztools.', 'difficulty': 500, 'language': 'English', 'questions': [{'choices': [{'answer': 'a)', 'correct': True}, {'answer': 'b)', 'correct': True}, {'answer': 'c)', 'correct': False}, {'answer': 'd)', 'correct': True}], 'iframe': {'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>Which of the following cities are capitals?</p><hr><p class='answer'><span class='letter'>a)</span> Bern</p><hr><p class='answer'><span class='letter'>b)</span> Kigali</p><hr><p class='answer'><span class='letter'>c)</span> New York</p><hr><p class='answer'><span class='letter'>d)</span> Ottawa</p></body></html>"}, 'image': '', 'numberOfAnswers': 4, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': {'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0}}, {'choices': [{'answer': 'a)', 'correct': False}, {'answer': 'b)', 'correct': False}, {'answer': 'c)', 'correct': False}, {'answer': 'd)', 'correct': True}], 'iframe': {'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>What is the capital of Norway?</p><hr><p class='answer'><span class='letter'>a)</span> Helsinki</p><hr><p class='answer'><span class='letter'>b)</span> Denmark</p><hr><p class='answer'><span class='letter'>c)</span> Drammen</p><hr><p class='answer'><span class='letter'>d)</span> Oslo</p></body></html>"}, 'image': '', 'numberOfAnswers': 4, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': {'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0}}, {'choices': [{'answer': 'a)', 'correct': True}, {'answer': 'b)', 'correct': False}, {'answer': 'c)', 'correct': False}], 'iframe': {'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>This is a very famous quote:\n\n<p>\n<blockquote>\n <em>Premature optimization is the root of all evil.</em>\n</blockquote>\n\nThis quote is attributed to</p><hr><p class='answer'><span class='letter'>a)</span> Donald Knuth</p><hr><p class='answer'><span class='letter'>b)</span> Ole-Johan Dahl</p><hr><p class='answer'><span class='letter'>c)</span> George W. Bush</p></body></html>"}, 'image': '', 'numberOfAnswers': 3, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': {'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0}}, {'choices': [{'answer': 'a)', 'correct': False}, {'answer': 'b)', 'correct': False}, {'answer': 'c)', 'correct': True}], 'iframe': {'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>Compute the result of \\( a+b \\) in the case \\( a=2 \\) and \\( b=2 \\).</p><hr><p class='answer'><span class='letter'>a)</span> 5.</p><hr><p class='answer'><span class='letter'>b)</span> The computation does not make sense when \\( a \\) and \\( b \\) are given without\nunits.</p><hr><p class='answer'><span class='letter'>c)</span> 4.</p></body></html>"}, 'image': '', 'numberOfAnswers': 3, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': {'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0}}, {'choices': [{'answer': 'a)', 'correct': False}, {'answer': 'b)', 'correct': False}, {'answer': 'c)', 'correct': True}, {'answer': 'd)', 'correct': True}], 'iframe': {'content': u"<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type='text/javascript' src='//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body><p class='question'>The equation\n\n$$\n\\begin{equation}\n\\nabla\\cdot\\boldsymbol{u} = 0\n\\label{cont:eq}\n\\end{equation}\n$$\n\nis famous in physics. Select the wrong assertion(s):</p><hr><p class='answer'><span class='letter'>a)</span> The equation tells that the vector field \\( \\boldsymbol{u} \\) is divergence free.</p><hr><p class='answer'><span class='letter'>b)</span> The equation implies that there exists a vector potential \\( \\boldsymbol{A} \\)\nsuch that \\( \\boldsymbol{u}=\\nabla\\times\\boldsymbol{A} \\).</p><hr><p class='answer'><span class='letter'>c)</span> The equation implies \\( \\nabla\\times\\boldsymbol{u}=0 \\).</p><hr><p class='answer'><span class='letter'>d)</span> The equation implies that \\( \\boldsymbol{u} \\) must be a constant vector field.</p></body></html>"}, 'image': '', 'keywords': ['gradient', 'divergence', 'curl', 'vector calculus'], 'numberOfAnswers': 4, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': {'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0}}, {'choices': [{'answer': 'a)', 'correct': True}, {'answer': 'b)', 'correct': False}, {'answer': 'c)', 'correct': False}], 'iframe': {'content': u'<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type=\'text/javascript\' src=\'//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\'></script></head><body><p class=\'question\'>We want to create a Python list object of length <code>n</code> where each\nelement is <code>0</code>. Is the following code then what we need?\n\n<p>\n\n<!-- code=python (!bc pycod) typeset with pygments style "default" -->\n<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span>\nmylist <span style="color: #666666">=</span> numpy<span style="color: #666666">.</span>zeros(n)\n</pre></div>\n<p></p><hr><p class=\'answer\'><span class=\'letter\'>a)</span> No.</p><hr><p class=\'answer\'><span class=\'letter\'>b)</span> Yes.</p><hr><p class=\'answer\'><span class=\'letter\'>c)</span> Yes, provided we write <code>np</code> instead of <code>numpy</code>:\n\n<p>\n\n<!-- code=python (!bc pycod) typeset with pygments style "default" -->\n<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>\nmylist <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(n)\n</pre></div>\n<p></p></body></html>'}, 'image': '', 'numberOfAnswers': 3, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': {'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0}}, {'choices': [{'answer': 'a)', 'correct': False}, {'answer': 'b)', 'correct': False}, {'answer': 'c)', 'correct': False}, {'answer': 'd)', 'correct': True}], 'iframe': {'content': u'<html><head>\n <style>\n body {font-family:sans-serif;\n font-size:14pt;}\n .question {font-size:22pt;\n font-weight:bold;}\n .answer {}\n .letter {font-weight:bold;}\n </style>\n <script type=\'text/javascript\' src=\'//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\'></script></head><body><p class=\'question\'><p>\n\n<!-- code=python (!bc pypro) typeset with pygments style "default" -->\n<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">math</span> <span style="color: #008000; font-weight: bold">import</span> sin\n\n<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">D</span>(u, t, dt<span style="color: #666666">=1E-5</span>):\n <span style="color: #008000; font-weight: bold">return</span> (u(t <span style="color: #666666">+</span> dt) <span style="color: #666666">-</span> u(t <span style="color: #666666">-</span> dt))<span style="color: #666666">/</span>(<span style="color: #666666">2*</span>dt)\n\n<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">u</span>(t):\n <span style="color: #BA2121">"A quadratic function."</span>\n <span style="color: #008000; font-weight: bold">return</span> t<span style="color: #666666">^2</span>\n\n<span style="color: #008000; font-weight: bold">print</span> D(u, t<span style="color: #666666">=4</span>),\n<span style="color: #008000; font-weight: bold">print</span> D(<span style="color: #008000; font-weight: bold">lambda</span> x: <span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">2*</span>x, <span style="color: #666666">2</span>)\n</pre></div>\n<p>\nThe purpose of this program is to differentiate the two mathematical\nfunctions\n\n$$\n\\begin{align*}\nu(t) &= t^2,\\\\\nf(x) &= 2x.\n\\end{align*}\n$$\n\nDetermine which of the following assertions that is <b>wrong</b>.</p><hr><p class=\'answer\'><span class=\'letter\'>a)</span> The <code>D</code> function computes an approximate derivative of the\nfunction <code>u(t)</code>.</p><hr><p class=\'answer\'><span class=\'letter\'>b)</span> The call <code>D(lambda x: return 2*x, 2)</code> is equivalent to defining\n\n<p>\n\n<!-- code=python (!bc pycod) typeset with pygments style "default" -->\n<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">f</span>(x):\n <span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">2*</span>x\n</pre></div>\n<p>\nand then calling <code>D(f, 2)</code>.</p><hr><p class=\'answer\'><span class=\'letter\'>c)</span> The string in the <code>u</code> function is a valid doc string.</p><hr><p class=\'answer\'><span class=\'letter\'>d)</span> One cannot use <code>u</code> both inside the <code>D</code> function and in the\nouter calling code (the main program).</p></body></html>'}, 'image': '', 'numberOfAnswers': 4, 'points': True, 'question': '', 'questionFormat': 2, 'time': 60000, 'video': {'endTime': 0, 'id': '', 'service': 'youtube', 'startTime': 0}}], 'quizType': 'quiz', 'title': 'Test', 'type': 'quiz', 'visibility': 0} from deep_eq import deep_eq success = deep_eq(expected, computed) #print success assert success
def test(): class TestNameSpace(): pass print "TESTING CCArgumentsParser..." parser = CCArgumentParser("gcc") ns = parser.parse_args(shlex.split("-E in.c"), TestNameSpace()) interp = CCArgumentInterpreter(ns) parser = CCArgumentParser("gcc") ns = parser.parse_args( shlex.split("-o out.o -c in.c --help -I/path -pthread"), TestNameSpace()) deep_eq(ns.unknown_flags, [], _assert=True) deep_eq(ns.output_kind, 'nooutput', _assert=True) deep_eq(ns.outputs, ["out.o"], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "in.c")], _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), None, _assert=True) deep_eq(interp.has_cc_phase('CC'), False, _assert=True) deep_eq(interp.cc_phase_inputs('CC'), [], _assert=True) deep_eq(interp.all_cc_inputs(), [], _assert=True) deep_eq(interp.all_cc_outputs(), [], _assert=True) deep_eq(interp.is_ld_kind("program"), False, _assert=True) deep_eq(interp.has_final_link(), False, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) ns = parser.parse_args( shlex.split("-o out.o -c in.c -print-search-dirs"), TestNameSpace()) deep_eq(ns.output_kind, 'nooutput', _assert=True) deep_eq(ns.outputs, ["out.o"], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "in.c")], _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), [], _assert=True) ns = parser.parse_args(shlex.split("-o out.o -c in.c -dumpversion"), TestNameSpace()) deep_eq(ns.output_kind, 'nooutput', _assert=True) deep_eq(ns.outputs, ["out.o"], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "in.c")], _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), [], _assert=True) ns = parser.parse_args(shlex.split("-o out.o -c in.c --version"), TestNameSpace()) deep_eq(ns.output_kind, 'nooutput', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.all_cc_outputs(), [], _assert=True) ns = parser.parse_args(shlex.split("-o out -E in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'preprocessed', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), "CPP", _assert=True) deep_eq(interp.all_cc_outputs(), ["out"], _assert=True) deep_eq(interp.all_cc_inputs(), ["in.c"], _assert=True) deep_eq(interp.has_cc_phase("CPP"), True, _assert=True) deep_eq(interp.has_cc_phase("CC"), False, _assert=True) deep_eq(interp.has_cc_phase("LD"), False, _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in.c"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), [], _assert=True) ns = parser.parse_args(shlex.split("-o out -M in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'dependencies', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), None, _assert=True) deep_eq(interp.all_cc_inputs(), [], _assert=True) deep_eq(interp.all_cc_outputs(), [], _assert=True) ns = parser.parse_args(shlex.split("-o out -MM in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'dependencies', _assert=True) ns = parser.parse_args(shlex.split("-o out -c in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'object', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), "AS", _assert=True) deep_eq(interp.all_cc_inputs(), ["in.c"], _assert=True) deep_eq(interp.all_cc_outputs(), ["out"], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in.c"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), [], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), [], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), [], _assert=True) ns = parser.parse_args(shlex.split("-S in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'assembly', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.last_cc_phase(), "CC", _assert=True) deep_eq(interp.all_cc_inputs(), ["in.c"], _assert=True) deep_eq(interp.all_cc_outputs(), ["in.s"], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in.c"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), [], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), [], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), [], _assert=True) ns = parser.parse_args( shlex.split("-S in1.c in2.c in3.i in4.ii in5.s in6.o in7.S"), TestNameSpace()) deep_eq(ns.output_kind, 'assembly', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.has_cc_phase("CC"), True, _assert=True) deep_eq(interp.has_cc_phase("CPP"), True, _assert=True) deep_eq(interp.last_cc_phase(), "CC", _assert=True) deep_eq(interp.all_cc_outputs(), ["in1.s", "in2.s", "in3.s", "in4.s"], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in1.c", "in2.c"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), ["in3.i", "in4.ii"], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), [], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), [], _assert=True) ns = parser.parse_args( shlex.split("-c /a/in1.c ./in2.c in3.i in4.ii in5.s in6.o in7.S"), TestNameSpace()) deep_eq(ns.output_kind, 'object', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.has_cc_phase("AS"), True, _assert=True) deep_eq(interp.has_cc_phase("CC"), True, _assert=True) deep_eq(interp.has_cc_phase("CPP"), True, _assert=True) deep_eq(interp.last_cc_phase(), "AS", _assert=True) deep_eq(interp.all_cc_outputs(), ["in1.o", "in2.o", "in3.o", "in4.o", "in5.o", "in7.o"], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["/a/in1.c", "./in2.c", "in7.S"], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), ["in3.i", "in4.ii"], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), ["in5.s"], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), [], _assert=True) ns = parser.parse_args( shlex.split( "-o all.exe in1.c in2.c in3.i in4.ii in5.s in6.o in7.S"), TestNameSpace()) deep_eq(ns.output_kind, "executable", _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("program"), True, _assert=True) deep_eq(interp.has_final_link(), True, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) deep_eq(interp.has_cc_phase("AS"), True, _assert=True) deep_eq(interp.has_cc_phase("CC"), True, _assert=True) deep_eq(interp.has_cc_phase("CPP"), True, _assert=True) deep_eq(interp.has_cc_phase("LD"), True, _assert=True) deep_eq(interp.last_cc_phase(), "LD", _assert=True) deep_eq(interp.all_cc_outputs(), ["all.exe"], _assert=True) deep_eq(interp.cc_phase_input_pairs("CPP"), [('SRC_C', "in1.c"), ('SRC_C', "in2.c"), ('SRC_SPP', "in7.S")], _assert=True) deep_eq(interp.cc_phase_inputs("CPP"), ["in1.c", "in2.c", "in7.S"], _assert=True) deep_eq(interp.cc_phase_input_pairs("CC"), [('SRC_I', "in3.i"), ('SRC_II', "in4.ii")], _assert=True) deep_eq(interp.cc_phase_inputs("CC"), ["in3.i", "in4.ii"], _assert=True) deep_eq(interp.cc_phase_input_pairs("AS"), [('SRC_S', "in5.s")], _assert=True) deep_eq(interp.cc_phase_inputs("AS"), ["in5.s"], _assert=True) deep_eq(interp.cc_phase_input_pairs("LD"), [('SRC_LNK', "in6.o")], _assert=True) deep_eq(interp.cc_phase_inputs("LD"), ["in6.o"], _assert=True) ns = parser.parse_args(shlex.split("-o out -r in.o"), TestNameSpace()) deep_eq(ns.output_kind, 'relocatable', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("relocatable"), True, _assert=True) deep_eq(interp.has_final_link(), False, _assert=True) deep_eq(interp.has_reloc_link(), True, _assert=True) ns = parser.parse_args(shlex.split("-o out in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'executable', _assert=True) deep_eq(ns.exec_kind, 'program', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("program"), True, _assert=True) ns = parser.parse_args(shlex.split("-o out -static in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'executable', _assert=True) deep_eq(ns.exec_kind, 'program', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("program"), True, _assert=True) ns = parser.parse_args(shlex.split("-o out -shared -static in.c"), TestNameSpace()) deep_eq(ns.output_kind, 'executable', _assert=True) deep_eq(ns.exec_kind, 'shared', _assert=True) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("shared"), True, _assert=True) deep_eq(interp.has_final_link(), True, _assert=True) deep_eq(interp.has_reloc_link(), False, _assert=True) ns = parser.parse_args( shlex.split("-o out.o -c -finline -Wall " "file1.c file2.cpp file3.cpp file4.s " "-Wother -mtune=i586 " "-Xpreprocessor pfile -Wp,-optp " "-Xassembler afile -Wa,-opta " "-Xlinker -optl -Wl,lfile " "-shared -not-an-option"), TestNameSpace()) deep_eq(ns.outputs, ["out.o"], _assert=True) deep_eq(ns.input_pairs, [('SRC_C', "file1.c"), ('SRC_CC', "file2.cpp"), ('SRC_CC', "file3.cpp"), ('SRC_S', "file4.s")], _assert=True) deep_eq(ns.preprocessor_flags, ["pfile", "-optp"], _assert=True) deep_eq(ns.assembler_flags, ["afile", "-opta"], _assert=True) deep_eq(ns.linker_flags, ["-optl", "lfile"], _assert=True) deep_eq(ns.output_kind, 'object', _assert=True) deep_eq(ns.exec_kind, 'shared', _assert=True) deep_eq(ns.unknown_flags, ['-not-an-option'], _assert=True) deep_eq(ns.input_pairs, [ ('SRC_C', "file1.c"), ('SRC_CC', "file2.cpp"), ('SRC_CC', "file3.cpp"), ('SRC_S', "file4.s"), ], _assert=True) tmpdir = tempfile.mkdtemp() f = open("%s/liba.a" % tmpdir, 'w') print >> f, "// An archive" f.close() f = open("%s/liba.so" % tmpdir, 'w') print >> f, "// A shared object" f.close() f = open("%s/libb.a" % tmpdir, 'w') print >> f, "// An archive" f.close() f = open("%s/libc.so" % tmpdir, 'w') print >> f, "// A shared object" f.close() f = open("%s/libd.so" % tmpdir, 'w') print >> f, "// An unreadable shared object" f.close() os.chmod("%s/libd.so" % tmpdir, 0000) f = open("%s/libe.a" % tmpdir, 'w') print >> f, "// An unreadable archive" f.close() os.chmod("%s/libe.a" % tmpdir, 0000) f = open("%s/include.gch" % tmpdir, 'w') print >> f, "// An unreadable pre-compiled header" f.close() ns = parser.parse_args( shlex.split("-o out.so -shared -L. -Lundef -L%s " "file1.c file2.cpp file3.o " "-x c a_c_file b_c_file -x none " ".libs/lib1.so l2.a " "-x cpp-output i_file -x c++cpp-output ii_file " "-include %s/include " "-lundef -la -lb -lc -ld -le" "-shared" % (tmpdir, tmpdir)), TestNameSpace()) interp = CCArgumentInterpreter(ns) deep_eq(interp.is_ld_kind("shared"), True, _assert=True) deep_eq(interp.all_cc_inputs(), [ "%s/include.gch" % tmpdir, "file1.c", "file2.cpp", "file3.o", "a_c_file", "b_c_file", ".libs/lib1.so", "l2.a", "i_file", "ii_file" ] + map(lambda x: os.path.join(tmpdir, x), ["liba.so", "libb.a", "libc.so"]), _assert=True) deep_eq(interp.cc_phase_input_pairs("CMD"), [('SRC_PCH', "%s/include.gch" % tmpdir)], _assert=True) deep_eq(interp.all_pch_inputs(), ["%s/include.gch" % tmpdir], _assert=True) deep_eq(interp.cc_phase_input_pairs("CPP"), [('SRC_C', "file1.c"), ('SRC_CC', "file2.cpp"), ('SRC_C', "a_c_file"), ('SRC_C', "b_c_file")], _assert=True) deep_eq(interp.cc_phase_input_pairs("CC"), [('SRC_I', "i_file"), ('SRC_II', "ii_file")], _assert=True) deep_eq(interp.cc_phase_input_pairs("LD"), [('SRC_LNK', "file3.o"), ('SRC_LNK', ".libs/lib1.so"), ('SRC_LNK', "l2.a")] + map(lambda x: ('SRC_LNK', os.path.join(tmpdir, x)), ["liba.so", "libb.a", "libc.so"]), _assert=True) ns = parser.parse_args( shlex.split("-o out.o -c in.c " "-include %s/include-unk" % (tmpdir)), TestNameSpace()) interp = CCArgumentInterpreter(ns) shutil.rmtree(tmpdir) print "SUCCESS CCArgumentsParser" return True
def test(): print "TESTING: ARInterpreter..." ar = ARInterpreter( {'args': shlex.split("ar cru lib.a a.o b.o c.c"), 'cwd': "."}) assert(ar.is_wellformed() == True) deep_eq(ar.get_kind(), "AR", _assert=True) deep_eq(ar.get_output_files(), ["lib.a"], _assert=True) deep_eq(ar.get_output_files(), ["lib.a"], _assert=True) deep_eq(ar.get_input_pairs(), [('SRC_AR', "a.o"), ('SRC_AR', "b.o"), ('SRC_AR', "c.c")], _assert=True) deep_eq(ar.get_input_files(), ["a.o", "b.o", "c.c"], _assert=True) ar = ARInterpreter( {'args': shlex.split("ar -v"), 'cwd': "."}) deep_eq(ar.get_output_files(), [], _assert=True) print "SUCCESS: ARInterpreter" return True