Skip to content

Commit

Permalink
- Removed additional code. (#5)
Browse files Browse the repository at this point in the history
Inputs are now more flexible.
  • Loading branch information
miroslavpojer authored Jun 21, 2024
1 parent 61c9cc9 commit f2e8dd1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
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

0 comments on commit f2e8dd1

Please sign in to comment.