diff --git a/src/sinol_make/util.py b/src/sinol_make/util.py index ab0e7167..dfd81005 100644 --- a/src/sinol_make/util.py +++ b/src/sinol_make/util.py @@ -30,22 +30,28 @@ def get_commands(): return commands -def check_if_package(): +def find_and_chdir_package(): """ - Function to check if current directory is a package + Checks if current directory or parent directory is a package directory. + If it is, it changes the current working directory to it and returns True. + If it isn't, it returns False. """ - - cwd = os.getcwd() - if os.path.exists(os.path.join(cwd, 'config.yml')): + if os.path.exists(os.path.join(os.getcwd(), 'config.yml')): + return True + elif os.path.exists(os.path.join(os.getcwd(), '..', 'config.yml')): + os.chdir('..') return True - return False + else: + return False def exit_if_not_package(): """ - Function that exits if current directory is not a package + Checks if current directory or parent directory is a package directory. + If it is, current working directory is changed to it. + If it isn't, it exits with an error. """ - if not check_if_package(): + if not find_and_chdir_package(): exit_with_error('You are not in a package directory (couldn\'t find config.yml in current directory).') @@ -292,7 +298,7 @@ def make_version_changes(): # In version 1.5.9 we changed the format of sinol_expected_scores. # Now all groups have specified points and status. - if check_if_package(): + if find_and_chdir_package(): with open("config.yml", "r") as config_file: config = yaml.load(config_file, Loader=yaml.FullLoader) diff --git a/tests/commands/run/test_integration.py b/tests/commands/run/test_integration.py index 84dd9b19..c879bb6e 100644 --- a/tests/commands/run/test_integration.py +++ b/tests/commands/run/test_integration.py @@ -632,3 +632,17 @@ def test(file_to_change, lang, comment_character): test("liblib.cpp", "cpp", "//") test("liblib.h", "cpp", "//") test("liblib.py", "py", "#") + + +@pytest.mark.parametrize("create_package", [get_simple_package_path()], indirect=True) +def test_cwd_in_prog(create_package): + """ + Test if `sinol-make` works when cwd is in prog. + """ + package_path = create_package + os.chdir("prog") + create_ins_outs(package_path) + parser = configure_parsers() + args = parser.parse_args(["run"]) + command = Command() + command.run(args)