Skip to content

Commit

Permalink
Merge pull request #1308 from buildtesters/fix_buildtest_buildspec_edit
Browse files Browse the repository at this point in the history
fix bug in 'buildtest bc edit' where test were not opening in editor
  • Loading branch information
shahzebsiddiqui authored Dec 8, 2022
2 parents cef47a5 + bba63db commit 5f36c11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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

0 comments on commit 5f36c11

Please sign in to comment.