diff --git a/api/client2.py b/api/client2.py index 0368f5d..3127e42 100644 --- a/api/client2.py +++ b/api/client2.py @@ -67,10 +67,11 @@ def __graph_results(self, description, result): print("Nothing to graph.") def run_specific(self, specific_query): - print(f"Processing {specific_query} ...") + # print(f"Processing {specific_query} ...") description, result = self.__process_query(specific_query) - print(f"Result for {specific_query}:") - print(description) + # print(f"Result for {specific_query}:") + + res=None if self.interactive: graph = input("Would you like to graph the results?(Y/n)") if graph == 'Y': @@ -82,9 +83,10 @@ def run_specific(self, specific_query): print(res) else: for res in result: - res = self.__adjust_results(res) print(res) - + print() + res = self.__adjust_results(res) + print(res) def run(self): for filename in os.listdir(self.QueryDir): @@ -100,12 +102,11 @@ def run(self): self.__graph_results(description, result) else: print(f"Result for {query_file}:") - print("here") print(self.__adjust_results(result)) else: - #print(f"Result for {query_file}:") - #print(self.__adjust_results(result)) + print(f"Result for {query_file}:") + print(self.__adjust_results(result)) if self.target_dir: with open(f"{self.target_dir}{filename[:-5]}_result.txt", 'w') as file: print(result, file=file) diff --git a/test/API/tester.py b/test/API/tester.py index b4c4fa6..3560d01 100644 --- a/test/API/tester.py +++ b/test/API/tester.py @@ -10,7 +10,7 @@ args_parser.add_argument("--target_dir", type=str, default="examples/actual/", help="Directory where to store the results of queries.") args_parser.add_argument("--specific", type=str, default=None, help="Specific query path.") - +args_parser.add_argument("--expected", type=str, default=None, help="Path to the expected result file.") my_venv = "../../../bakalarka/bin/python3" server = "../../api/Server2_1.py" @@ -21,7 +21,27 @@ def main(args): time.sleep(2) try: if (args.specific): - ... + try: + assert args.expected is not None + except AssertionError: + print("Missing the expected output.") + return + print("---TESTING SPECIFIC QUERY---") + client_process = subprocess.run([my_venv, client, f"--specific_query={args.specific}"], capture_output=True, text=True) + actual = client_process.stdout.strip() + f1 = open(args.expected, 'r') + expected = f1.read().strip() + + if (actual == expected): + print(f"Query {args.specific}: PASSED!") + else: + diff = difflib.unified_diff(expected.splitlines(), actual.splitlines(), + fromfile='expected', tofile='actual', lineterm='') + print(f"Query {args.specific}: FAILED!") + print("------------------------------") + for line in diff: + print(line) + print("------------------------------") else: print("---TESTING ALL QUERIES AT ONCE---") client_process = subprocess.run([my_venv, client, f"--query_source={args.source_dir}",