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

fix bug in 'buildtest bc edit' where test were not opening in editor #1308

Merged
merged 1 commit into from
Dec 8, 2022
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
13 changes: 7 additions & 6 deletions buildtest/cli/buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ def print_paths(self):
console.print(path)


def edit_buildspec_test(test_names, configuration, editor, test=None):
def edit_buildspec_test(test_names, configuration, editor):
"""Open a list of test names in editor mode defined by ``EDITOR`` environment otherwise resort to ``vim``.
This method will search for buildspec cache and find path to buildspec file corresponding to test name and open
file in editor. If multiple test are specified via ``buildtest buildspec edit-test`` then each file will be open and
Expand All @@ -996,7 +996,6 @@ def edit_buildspec_test(test_names, configuration, editor, test=None):
test_names (list): A list of test names to open in editor
configuration (buildtest.config.SiteConfiguration): An instance of SiteConfiguration class
editor (str): Path to editor to use when opening file
test (bool): A boolean to determine whether to open file for editing, by default `test=None` indicates file will be open in editor. If its True this method will return immediately which is useful when running regression test.
"""
cache = BuildspecCache(configuration=configuration)

Expand All @@ -1006,7 +1005,9 @@ def edit_buildspec_test(test_names, configuration, editor, test=None):
continue

buildspec = cache.lookup_buildspec_by_name(name)
if test is None:

# only used for regression testing to ensure test is not stuck for closing file
if not editor:
editor = "echo" # Doesnt call the editor.

subprocess.call([editor, buildspec])
Expand All @@ -1021,14 +1022,13 @@ def edit_buildspec_test(test_names, configuration, editor, test=None):
console.print(f"[green]{buildspec} is valid")


def edit_buildspec_file(buildspecs, configuration, editor, test=None):
def edit_buildspec_file(buildspecs, configuration, editor):
"""Open buildspec in editor and validate buildspec with parser. This method is invoked by command ``buildtest buildspec edit-file``.

Args:
buildspec (str): Path to buildspec file to edit
configuration (buildtest.config.SiteConfiguration): An instance of SiteConfiguration class
editor (str): Path to editor to use when opening file
test (bool): A boolean to determine whether to open file for editing, by default `test=None` indicates file will be open in editor. If its True this method will return immediately which is useful when running regression test.
"""
for file in buildspecs:

Expand All @@ -1038,7 +1038,8 @@ def edit_buildspec_file(buildspecs, configuration, editor, test=None):
f"buildspec: {buildspec} is a directory, please specify a file type"
)
continue
if test is None:
# only used for regression testing to ensure test is not stuck for closing file
if not editor:
editor = "cat"
subprocess.call([editor, buildspec])

Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_edit_file():
edit_buildspec_file(
buildspecs=[os.path.join(BUILDTEST_ROOT, "tutorials", "vars.yml")],
configuration=configuration,
editor="",
editor=None,
)


Expand Down