Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 13, 2023
1 parent 7002643 commit 7780a7a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def run(self, args: argparse.Namespace):

self.args = args
self.task_id = package_util.get_task_id()
package_util.validate_files(self.task_id)
package_util.validate_test_names(self.task_id)

with open(os.path.join(os.getcwd(), 'config.yml'), 'r') as config_file:
config = yaml.load(config_file, Loader=yaml.FullLoader)
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def run(self, args: argparse.Namespace):

self.args = args
self.task_id = package_util.get_task_id()
package_util.validate_files(self.task_id)
package_util.validate_test_names(self.task_id)
self.ingen = gen_util.get_ingen(self.task_id, args.ingen_path)
print(util.info(f'Using ingen file {os.path.basename(self.ingen)}'))

Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/inwer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def run(self, args: argparse.Namespace):
util.exit_if_not_package()

self.task_id = package_util.get_task_id()
package_util.validate_files(self.task_id)
package_util.validate_test_names(self.task_id)
self.inwer = inwer_util.get_inwer_path(self.task_id, args.inwer_path)
if self.inwer is None:
if args.inwer_path is None:
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ def run(self, args):
util.exit_if_not_package()

self.set_constants()
package_util.validate_files(self.ID)
package_util.validate_test_names(self.ID)
self.args = args
with open(os.path.join(os.getcwd(), "config.yml"), 'r') as config:
try:
Expand Down
11 changes: 3 additions & 8 deletions src/sinol_make/helpers/package_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,14 @@ def get_memory_limit(test_path, config, lang, args=None):
return _get_limit(LimitTypes.MEMORY_LIMIT, test_path, str_config, lang)


def validate_files(task_id):
def validate_test_names(task_id):
"""
Checks if all files in the package have valid names.
"""
def get_invalid_files(path, *patterns):
def get_invalid_files(path, pattern):
invalid_files = []
for file in glob.glob(os.path.join(os.getcwd(), path)):
invalid = True
for pattern in patterns:
if pattern.match(os.path.basename(file)):
invalid = False
break
if invalid:
if not pattern.match(os.path.basename(file)):
invalid_files.append(os.path.basename(file))
return invalid_files

Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/test_package_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ def test_validate_files(create_package, capsys):
util.create_ins_outs(package_path)
task_id = package_util.get_task_id()
assert task_id == "abc"
package_util.validate_files(task_id)
package_util.validate_test_names(task_id)

os.rename(os.path.join(package_path, "in", "abc1a.in"), os.path.join(package_path, "in", "def1a.in"))
with pytest.raises(SystemExit):
package_util.validate_files(task_id)
package_util.validate_test_names(task_id)
out = capsys.readouterr().out
assert "def1a.in" in out

os.rename(os.path.join(package_path, "in", "def1a.in"), os.path.join(package_path, "in", "abc1a.in"))
os.rename(os.path.join(package_path, "out", "abc1a.out"), os.path.join(package_path, "out", "def1a.out"))
with pytest.raises(SystemExit):
package_util.validate_files(task_id)
package_util.validate_test_names(task_id)
out = capsys.readouterr().out
assert "def1a.out" in out

0 comments on commit 7780a7a

Please sign in to comment.