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

Make paths more flexible #5

Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ This action scans the specified `paths` for project files and checks if their fi
- **Example**: `*UnitTest.*,*IntegrationTest.*`

### `paths`
- **Description**: List of directories to include in the glob pattern check, separated by commas.
- **Description**: List of paths to include in the glob pattern check, separated by commas.
- **Required**: Yes
- **Example**: `**/src/test/java/**,**/src/test/scala/**`
- **Example**: `**/src/test/java/**,**/src/test/scala/**/*.txt`

### `excludes`
- **Description**: List of filenames to exclude from glob pattern checks, separated by commas.
Expand Down
4 changes: 0 additions & 4 deletions src/filename_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ def find_non_matching_files(name_patterns, paths, excludes):

# Iterate over each glob pattern to find files
for path in paths:
if '.' in path:
logging.error(f"Skipped path to file value '{path}'. Only path to directories are accepted.")
continue

for file in glob.glob(path, recursive=True):
# Check if the file matches any of the exclude patterns
if any(fnmatch.fnmatch(file, e) for e in excludes):
Expand Down
18 changes: 9 additions & 9 deletions tests/test_filename_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_set_action_output_env_var_set():
with patch.dict(os.environ, {'GITHUB_OUTPUT': tmpfile.name}):
set_action_output('test_name', 'test_value')
tmpfile.seek(0)
assert tmpfile.read().decode() == 'test_name=test_value\n'
assert 'test_name=test_value\n' == tmpfile.read().decode()


def test_set_action_output_env_var_not_set():
Expand All @@ -92,7 +92,7 @@ def test_set_action_output_parametrized(name, value, expected):
with patch.dict(os.environ, {'GITHUB_OUTPUT': tmpfile.name}):
set_action_output(name, value)
tmpfile.seek(0)
assert tmpfile.read().decode() == expected
assert expected == tmpfile.read().decode()


def test_get_action_input(mock_getenv):
Expand All @@ -109,8 +109,8 @@ def test_set_failed():
# Test the SystemExit exception
with pytest.raises(SystemExit) as pytest_wrapped_e:
set_action_failed(test_message)
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
assert SystemExit == pytest_wrapped_e.type
assert 1 == pytest_wrapped_e.value.code

# Ensure logging.error was called with the correct message
mock_log_error.assert_called_once_with(test_message)
Expand All @@ -119,7 +119,7 @@ def test_set_failed():
@pytest.mark.parametrize(
"paths, report_format, verbose_logging, excludes, fail_on_violation, expected_violation_count, expected_report, expected_failed_message", [
(PATHS, REPORT_FORMAT_CONSOLE, VERBOSE_LOGGING_FALSE, EXCLUDES_EMPTY, FAIL_ON_VIOLATION_FALSE, 4, None, None), # default values
(PATHS_WITH_FILE, REPORT_FORMAT_CONSOLE, VERBOSE_LOGGING_FALSE, EXCLUDES_EMPTY, FAIL_ON_VIOLATION_FALSE, 4, None, None),
(PATHS_WITH_FILE, REPORT_FORMAT_CONSOLE, VERBOSE_LOGGING_FALSE, EXCLUDES_EMPTY, FAIL_ON_VIOLATION_FALSE, 6, None, None),
(PATHS, REPORT_FORMAT_CONSOLE, VERBOSE_LOGGING_TRUE, EXCLUDES, FAIL_ON_VIOLATION_FALSE, 2, None, None),
(PATHS, REPORT_FORMAT_CSV, VERBOSE_LOGGING_FALSE, EXCLUDES_EMPTY, FAIL_ON_VIOLATION_FALSE, 4, 'violations.csv', None),
(PATHS, REPORT_FORMAT_JSON, VERBOSE_LOGGING_FALSE, EXCLUDES_EMPTY, FAIL_ON_VIOLATION_FALSE, 4, 'violations.json', None),
Expand All @@ -141,18 +141,18 @@ def getenv_mock(key, default=''):
with (patch('src.filename_inspector.set_action_output', new=mock_set_action_output),
patch('src.filename_inspector.set_action_failed', new=mock_set_action_failed)):
run()
assert output_values['violation-count'] == str(expected_violation_count)
assert str(expected_violation_count) == output_values['violation-count']
if expected_report:
assert output_values['report-path'] == expected_report
assert expected_report == output_values['report-path']
if expected_failed_message:
assert failed_message == expected_failed_message
assert expected_failed_message == failed_message


def test_run_exception_handling():
with patch('src.filename_inspector.get_action_input', side_effect=Exception('Test exception')), \
patch('src.filename_inspector.set_action_failed', new=mock_set_action_failed):
run()
assert failed_message == 'Action failed with error: Test exception'
assert 'Action failed with error: Test exception' == failed_message


# Run the tests
Expand Down