Skip to content
Closed
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
52 changes: 46 additions & 6 deletions tests/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def _file_change(filename: str) -> FileChange:
return FileChange(
pr_number=0,
repository_full_name='nextcloud/android',
repository_full_name='example/repo',
filename=filename,
changes=10,
additions=10,
Expand Down Expand Up @@ -35,41 +35,81 @@ def test_is_test_file_detects_gradle_test_source_sets(filename):
@pytest.mark.parametrize(
'filename',
[
# Real files in mastodon/mastodon spec/ tree (verified via Contents API).
'spec/models/account_spec.rb',
'spec/models/account_alias_spec.rb',
'spec/models/account_conversation_spec.rb',
'spec/services/account_search_service_spec.rb',
'spec/rails_helper.rb',
'spec/support/factory_bot.rb',
'engines/users/spec/models/user_spec.rb',
'spec/services/after_block_service_spec.rb',
'spec/controllers/application_controller_spec.rb',
'spec/controllers/follower_accounts_controller_spec.rb',
# *_spec.rb outside spec/ — filename pattern alone must catch.
'lib/foo_spec.rb',
'app/models/user_spec.rb',
# Other RSpec-style ecosystems using underscore-spec naming.
'src/util_spec.js',
'pkg/handler_spec.ts',
],
)
def test_is_test_file_detects_rspec_underscore_spec_suffix(filename):
assert _file_change(filename).is_test_file() is True


@pytest.mark.parametrize(
'filename',
[
# RSpec helper/support files that don't end in _spec.rb but live in spec/.
'spec/rails_helper.rb',
'spec/support/factory_bot.rb',
'spec/support/database_cleaner.rb',
'spec/support/shared_examples.rb',
# Nested spec/ at non-root.
'engines/users/spec/models/user_spec.rb',
'engines/users/spec/factories.rb',
],
)
def test_is_test_file_detects_rspec_conventions(filename):
def test_is_test_file_detects_spec_directory(filename):
assert _file_change(filename).is_test_file() is True


@pytest.mark.parametrize(
'filename',
[
# Lookalikes that must NOT trip the new patterns.
# Filename "spec" prefix without trailing underscore-dot.
'app/build.gradle.kts',
'src/main/java/com/example/Bar.java',
'docs/androidtest.md',
'tools/androidtestutils.py',
'app/models/specification.rb',
'src/spectrum.rb',
'lib/spectrum.rb',
'app/models/respec.rb',
'lib/aspec.rb',
'lib/inspector.rb',
'src/spec.rb',
'src/spec.js',
'config/spec.rb',
# Pre-existing patterns must continue to reject ordinary source.
'app/models/account.rb',
'lib/foo.rb',
'src/main.py',
'src/foo/bar.py',
],
)
def test_is_test_file_rejects_non_test_lookalikes(filename):
assert _file_change(filename).is_test_file() is False


def test_is_test_file_preserves_existing_test_conventions():
assert _file_change('tests/test_foo.py').is_test_file() is True
assert _file_change('src/tests/test_foo.py').is_test_file() is True
assert _file_change('src/__tests__/foo.test.js').is_test_file() is True
assert _file_change('pkg/foo_test.go').is_test_file() is True
assert _file_change('src/foo/bar.py').is_test_file() is False
assert _file_change('app/foo_tests.rb').is_test_file() is True
assert _file_change('src/foo.spec.js').is_test_file() is True
assert _file_change('app/spec_helper.rb').is_test_file() is True
assert _file_change('app/test_helper.py').is_test_file() is True


def test_pull_request_handles_deleted_label_event():
Expand Down
Loading