Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix in rename_rms_scripts #204

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tests = [
"pytest-cov",
"pytest-runner",
"pytest-xdist",
"pytest-mock",
"rstcheck",
"types-PyYAML",
]
Expand Down
6 changes: 3 additions & 3 deletions src/fmu/tools/rms/rename_rms_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@ def main() -> None:

logging.basicConfig()

if args.verbose or args.test:
if args.verbose or args.test_run:
_logger.setLevel(logging.INFO)

# Don't write files if it's a test run
master = PythonCompMaster(args.path, write=not args.test)
master = PythonCompMaster(args.path, write=not args.test_run)

if args.backup:
_make_backup(master.parent)
Expand All @@ -522,7 +522,7 @@ def main() -> None:
master.write_master_file()
_print_skipped(skipped, master)

if args.verbose or args.test:
if args.verbose or args.test_run:
unused = master.get_unused_scripts()
_print_unused(unused, master)

Expand Down
33 changes: 31 additions & 2 deletions tests/rms/test_rename_rms_scripts.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
from filecmp import cmp
from os import listdir
from os import chdir, listdir
from pathlib import Path
from shutil import copytree
from textwrap import dedent

import pytest
from fmu.tools.rms.rename_rms_scripts import PythonCompMaster
from fmu.tools.rms.rename_rms_scripts import PythonCompMaster, main

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -248,3 +248,32 @@ def test_write_master_file(tmp_path):
assert cmp(exp_py / ".master", project.path) is True

assert set(listdir(exp_py)) == set(listdir(project.parent))


def test_cmdline_main(tmp_path, mocker):
"""Test the cmndline utility runs without errors. Both with and
without test-run option.
"""
project_path = tmp_path / "snakeoil.rms13.0.3"
copytree(TESTPROJ, project_path)

mocker.patch("sys.argv", ["rename_rms_scripts", str(project_path)])
main()

mocker.patch("sys.argv", ["rename_rms_scripts", str(project_path)], "--test-run")
main()


def test_cmdline_main_backup(tmp_path, mocker):
"""Test the backup of the pythoncomp through the cmndline."""
project_path = tmp_path / "snakeoil.rms13.0.3"
copytree(TESTPROJ, project_path)

# change directory to store the backup in the tmp_path
chdir(tmp_path)

mocker.patch("sys.argv", ["rename_rms_scripts", str(project_path), "--backup"])
main()

# check that the backup exists
assert (tmp_path / "backup_pythoncomp").exists()
Loading