|
2 | 2 | # Author of the original code: Bartosz Kostka <[email protected]>
|
3 | 3 | # Version 0.6 (2021-08-29)
|
4 | 4 | import subprocess
|
| 5 | +import glob |
5 | 6 |
|
6 | 7 | from sinol_make.commands.run.structs import ExecutionResult, ResultChange, ValidationResult, ExecutionData, PointsChange
|
7 | 8 | from sinol_make.helpers.parsers import add_compilation_arguments
|
@@ -155,6 +156,10 @@ def get_output_file(self, test_path):
|
155 | 156 | return os.path.join("out", os.path.split(os.path.splitext(test_path)[0])[1]) + ".out"
|
156 | 157 |
|
157 | 158 |
|
| 159 | + def get_groups(self, tests): |
| 160 | + return sorted(list(set([self.get_group(test) for test in tests]))) |
| 161 | + |
| 162 | + |
158 | 163 | def compile_solutions(self, solutions):
|
159 | 164 | os.makedirs(self.COMPILATION_DIR, exist_ok=True)
|
160 | 165 | os.makedirs(self.EXECUTABLES_DIR, exist_ok=True)
|
@@ -808,7 +813,7 @@ def exit(self):
|
808 | 813 |
|
809 | 814 | def set_scores(self):
|
810 | 815 | self.tests = package_util.get_tests(self.args.tests)
|
811 |
| - self.groups = list(sorted(set([self.get_group(test) for test in self.tests]))) |
| 816 | + self.groups = self.get_groups(self.tests) |
812 | 817 | self.scores = collections.defaultdict(int)
|
813 | 818 |
|
814 | 819 | if 'scores' not in self.config.keys():
|
@@ -846,6 +851,49 @@ def set_scores(self):
|
846 | 851 |
|
847 | 852 | self.possible_score = self.get_possible_score(self.groups)
|
848 | 853 |
|
| 854 | + def get_valid_input_files(self): |
| 855 | + """ |
| 856 | + Returns list of input files that have corresponding output file. |
| 857 | + """ |
| 858 | + output_tests = glob.glob(os.path.join(os.getcwd(), "out", "*.out")) |
| 859 | + output_tests_ids = [self.extract_test_id(test) for test in output_tests] |
| 860 | + valid_input_files = [] |
| 861 | + for test in self.tests: |
| 862 | + if self.extract_test_id(test) in output_tests_ids: |
| 863 | + valid_input_files.append(test) |
| 864 | + return valid_input_files |
| 865 | + |
| 866 | + def validate_existence_of_outputs(self): |
| 867 | + """ |
| 868 | + Checks if all input files have corresponding output files. |
| 869 | + """ |
| 870 | + valid_input_files = self.get_valid_input_files() |
| 871 | + if len(valid_input_files) != len(self.tests): |
| 872 | + missing_tests = list(set(self.tests) - set(valid_input_files)) |
| 873 | + missing_tests.sort() |
| 874 | + |
| 875 | + print(util.warning('Missing output files for tests: ' + ', '.join( |
| 876 | + [self.extract_file_name(test) for test in missing_tests]))) |
| 877 | + print(util.warning('Running only on tests with output files.')) |
| 878 | + self.tests = valid_input_files |
| 879 | + self.groups = self.get_groups(self.tests) |
| 880 | + |
| 881 | + def check_are_any_tests_to_run(self): |
| 882 | + """ |
| 883 | + Checks if there are any tests to run and prints them and checks |
| 884 | + if all input files have corresponding output files. |
| 885 | + """ |
| 886 | + if len(self.tests) > 0: |
| 887 | + print(util.bold('Tests that will be run:'), ' '.join([self.extract_file_name(test) for test in self.tests])) |
| 888 | + |
| 889 | + example_tests = [test for test in self.tests if self.get_group(test) == 0] |
| 890 | + if len(example_tests) == len(self.tests): |
| 891 | + print(util.warning('Running only on example tests.')) |
| 892 | + |
| 893 | + self.validate_existence_of_outputs() |
| 894 | + else: |
| 895 | + print(util.warning('There are no tests to run.')) |
| 896 | + |
849 | 897 | def check_errors(self, results: dict[str, dict[str, dict[str, ExecutionResult]]]):
|
850 | 898 | error_msg = ""
|
851 | 899 | for solution in results:
|
@@ -909,15 +957,7 @@ def run(self, args):
|
909 | 957 | self.checker = None
|
910 | 958 |
|
911 | 959 | self.set_scores()
|
912 |
| - |
913 |
| - if len(self.tests) > 0: |
914 |
| - print(util.bold('Tests that will be run:'), ' '.join([self.extract_file_name(test) for test in self.tests])) |
915 |
| - |
916 |
| - example_tests = [test for test in self.tests if self.get_group(test) == 0] |
917 |
| - if len(example_tests) == len(self.tests): |
918 |
| - print(util.warning('Running only on example tests.')) |
919 |
| - else: |
920 |
| - print(util.warning('There are no tests to run.')) |
| 960 | + self.check_are_any_tests_to_run() |
921 | 961 |
|
922 | 962 | self.failed_compilations = []
|
923 | 963 | solutions = self.get_solutions(self.args.solutions)
|
|
0 commit comments