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 local run of python test cases #2565

Merged
merged 2 commits into from
Apr 16, 2023
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
- Increase auto-update-linters GitHub Action timeout
- Fix `/build` slash command to checkout the correct branch when called from PR, by @echoix in <https://github.com/oxsecurity/megalinter/pull/2542>
- Fix crash in case of unreachable symlinks
- Fix local run of python test cases

- Documentation

Expand Down
37 changes: 16 additions & 21 deletions megalinter/utilstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
)


# Returns root dir depending we are locally or in CI
def get_root_dir():
root_dir = (
DEFAULT_DOCKER_WORKSPACE_DIR
if os.path.isdir(DEFAULT_DOCKER_WORKSPACE_DIR)
else Repo(__file__, search_parent_directories=True).git.rev_parse(
"--show-toplevel"
)
)
return root_dir


# Define env variables before any test case
def linter_test_setup(params=None):
for key in [
Expand Down Expand Up @@ -74,13 +86,8 @@ def linter_test_setup(params=None):
else f"{os.path.sep}.automation{os.path.sep}test"
)
# Root path of default rules
root_dir = (
DEFAULT_DOCKER_WORKSPACE_DIR
if os.path.isdir(DEFAULT_DOCKER_WORKSPACE_DIR)
else os.path.relpath(
os.path.relpath(os.path.dirname(os.path.abspath(__file__))) + "/../../../.."
)
)
root_dir = get_root_dir()

workspace = None
config_file_path = root_dir + sub_lint_root + os.path.sep + ".mega-linter.yml"
if os.path.isfile(config_file_path):
Expand Down Expand Up @@ -334,13 +341,7 @@ def test_get_linter_version(linter, test_self):
version == version_cache, "Version not found in linter instance cache"
)
# Write in linter-versions.json
root_dir = (
DEFAULT_DOCKER_WORKSPACE_DIR
if os.path.isdir(DEFAULT_DOCKER_WORKSPACE_DIR)
else os.path.relpath(
os.path.relpath(os.path.dirname(os.path.abspath(__file__))) + "/../../../.."
)
)
root_dir = get_root_dir()
versions_file = (
root_dir + os.path.sep + "/.automation/generated/linter-versions.json"
)
Expand Down Expand Up @@ -399,13 +400,7 @@ def test_get_linter_help(linter, test_self):
help_txt == "ERROR", "Returned help invalid: [" + help_txt + "]"
)
# Write in linter-helps.json
root_dir = (
DEFAULT_DOCKER_WORKSPACE_DIR
if os.path.isdir(DEFAULT_DOCKER_WORKSPACE_DIR)
else os.path.relpath(
os.path.relpath(os.path.dirname(os.path.abspath(__file__))) + "/../../../.."
)
)
root_dir = get_root_dir()
helps_file = root_dir + os.path.sep + "/.automation/generated/linter-helps.json"
data = {}
help_lines = help_txt.splitlines()
Expand Down