def _test_cmd(self, task, testfile=None): problogcli = root_path('problog-cli.py') if testfile is None: testfile = [root_path('test', '7_probabilistic_graph.pl')] with open(os.devnull, 'w') as out: if task is None: self.assertEqual( subprocess_call([sys.executable, problogcli] + testfile, stdout=out), 0) else: self.assertEqual( subprocess_call([sys.executable, problogcli, task] + testfile, stdout=out), 0)
def test_cli_learn(self): problogcli = root_path('problog-cli.py') model = root_path('problog', 'learning', 'test1_model.pl') examples = root_path('problog', 'learning', 'test1_examples.pl') out = subprocess_check_output([sys.executable, problogcli, 'lfi', model, examples]) outline = out.strip().split() self.assertGreater(int(outline[-1]), 2) weights = [float(outline[i].strip('[],')) for i in (1, 2, 3, 4)] self.assertAlmostEqual(weights[0], 1.0 / 3) self.assertAlmostEqual(weights[2], 1.0) self.assertAlmostEqual(weights[3], 0.0)
def test(self): problogcli = root_path("problog-cli.py") model = filename examples = filename.replace(".pl", ".ev") if not os.path.exists(examples): raise Exception("Evidence file is missing: {}".format(examples)) out = subprocess_check_output([ sys.executable, problogcli, "lfi", "-n", "10", "-O", model.replace(".pl", ".l_pl"), model, examples, ]) outline = out.strip().split() print(outline)
if computed is None : self.assertEqual(correct, type(e).__name__) else : self.assertIsInstance( correct, dict ) self.assertSequenceEqual(correct, computed) for query in correct : self.assertAlmostEqual(correct[query], computed[query], msg=query) return test if __name__ == '__main__' : filenames = sys.argv[1:] else : filenames = glob.glob( root_path('test', '*.pl' ) ) for testfile in filenames : # testname = 'test_system_' + os.path.splitext(os.path.basename(testfile))[0] # setattr( TestSystemSDD, testname, createSystemTestSDD(testfile) ) # setattr( TestSystemNNF, testname, createSystemTestNNF(testfile) ) testname = 'test_system_' + os.path.splitext(os.path.basename(testfile))[0] setattr( TestSystemSDD, testname, createSystemTestSDD(testfile, True) ) setattr( TestSystemNNF, testname, createSystemTestNNF(testfile, True) ) if __name__ == '__main__' : suite = unittest.TestLoader().loadTestsFromTestCase(TestSystemSDD) unittest.TextTestRunner(verbosity=2).run(suite) suite = unittest.TestLoader().loadTestsFromTestCase(TestSystemNNF)
return test def ignore_previous_output(path): # dir_name = "../../test/lfi/unit_tests/" test = os.listdir(path) for item in test: if item.endswith(".out"): os.remove(os.path.join(path, item)) if __name__ == "__main__": filenames = sys.argv[1:] else: AD_filenames = glob.glob(root_path("test", "lfi", "AD", "*.pl")) simple_filenames = glob.glob(root_path("test", "lfi", "Simple", "*.pl")) misc_filenames = glob.glob(root_path("test", "lfi", "Misc", "*.pl")) evaluatables = ["ddnnf"] # evaluatables = [] if has_sdd: evaluatables.append("sdd") evaluatables.append("sddx") else: print("No SDD support - The system tests are not performed with SDDs.") # tests for ADs for testfile in AD_filenames: testname = "test_lfi_AD_" + os.path.splitext(os.path.basename(testfile))[0]
) bn = formula_to_bn(gp) computed = str(bn).strip() except Exception as err: e = err computed = None if computed is None: self.assertEqual(correct, type(e).__name__) else: self.assertIsInstance(computed, str) self.assertEqual(correct, computed) return test if __name__ == "__main__": filenames = sys.argv[1:] else: filenames = glob.glob(root_path("test/bn", "*.pl")) for testfile in filenames: testname = "test_bn_" + os.path.splitext(os.path.basename(testfile))[0] setattr(TestBNGeneric, testname, createBNTestGeneric(testfile, True)) if __name__ == "__main__": suite = unittest.TestLoader().loadTestsFromTestCase(TestBNGeneric) unittest.TextTestRunner(verbosity=2).run(suite)
return test def ignore_previous_output(path): # dir_name = "../../test/lfi/unit_tests/" test = os.listdir(path) for item in test: if item.endswith(".l_pl"): os.remove(os.path.join(path, item)) if __name__ == "__main__": filenames = sys.argv[1:] else: ADfilenames = glob.glob(root_path("test", "lfi", "AD", "*.pl")) simple_filenames = glob.glob(root_path("test", "lfi", "simple", "*.pl")) useParents_filenames = glob.glob( root_path("test", "lfi", "useParents", "*.pl")) unit_test_filenames = glob.glob( root_path("test", "lfi", "unit_tests", "test_*.pl")) test_interface_filenames = glob.glob( root_path("test", "lfi", "test_interface", "test1_model.pl")) evaluatables = ["ddnnf"] if has_sdd: evaluatables.append("sdd") evaluatables.append("sddx") else: print("No SDD support - The system tests are not performed with SDDs.")