Skip to content

Commit

Permalink
chore: handle more warnings in test suite (pypi#10547)
Browse files Browse the repository at this point in the history
* chore: replace deprecated scalar method

SQLAlchemy 1.4.x deprecated the `.as_scalar()` method and replaced it
with `.scalar_subquery()` and issued a `SADeprecationWarning`.

Refs: https://docs.sqlalchemy.org/en/14/changelog/changelog_14.html#change-f413ff8c13a1fb7d766bfa16dfcdfbf1

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* test: ignore InsecureStorageWarning

When another class was added, it wasn't excluded from the warnings
report.

Refs: pypi#9792
Original ignore: pypi#4360

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* test: ignore CIText warnings in test output

The updated SQLAlchemy library now emits 2,000+ warnings for CIText().

I've opened an issue on the responsible repo.

Refs: mahmoudimus/sqlalchemy-citext#25

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* test: filter out known legacy behavior in test

The test case knowingly creates invalid versions, and the code handles
them by performing some extra validation, and throws the error.

Suppress the warnings for creating `LegacyVersion`.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* test: filter out SAWarning for invalidation

The collections used in the test case are intentionally being modified.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
  • Loading branch information
2 people authored and domdfcoding committed Jun 7, 2022
1 parent 3cd60d1 commit d89d523
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ markers = [
'functional: Slower running tests which test the entire system is functioning.',
]
filterwarnings = [
'ignore::warehouse.admin.services.InsecureStorageWarning',
'ignore::warehouse.packaging.services.InsecureStorageWarning',
'ignore:UserDefinedType CIText.*:sqlalchemy.exc.SAWarning' # See https://github.com/mahmoudimus/sqlalchemy-citext/issues/25
]
2 changes: 2 additions & 0 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_validates_valid_pep440_version(self, version):
form, field = pretend.stub(), pretend.stub(data=version)
legacy._validate_pep440_version(form, field)

@pytest.mark.filterwarnings("ignore:Creating a LegacyVersion.*:DeprecationWarning")
@pytest.mark.parametrize("version", ["dog", "1.0.dev.a1", "1.0+local"])
def test_validates_invalid_pep440_version(self, version):
form, field = pretend.stub(), pretend.stub(data=version)
Expand Down Expand Up @@ -992,6 +993,7 @@ def test_fails_invalid_version(self, pyramid_config, pyramid_request, version):
),
],
)
@pytest.mark.filterwarnings("ignore:Creating a LegacyVersion.*:DeprecationWarning")
def test_fails_invalid_post_data(
self, pyramid_config, db_request, post_data, message
):
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/packaging/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ def find_service(name=None):


class TestSyncBigQueryMetadata:
@pytest.mark.filterwarnings(
"ignore:This collection has been invalidated.:sqlalchemy.exc.SAWarning"
)
@pytest.mark.parametrize(
("release_files_table", "expected_get_table_calls"),
[
Expand Down
2 changes: 1 addition & 1 deletion warehouse/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def email(self):
return (
select([Email.email])
.where((Email.user_id == self.id) & (Email.primary.is_(True)))
.as_scalar()
.scalar_subquery()
)

@property
Expand Down
4 changes: 2 additions & 2 deletions warehouse/search/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _project_docs(db, project_name=None):
db.query(func.array_agg(r.version))
.filter(r.project_id == Release.project_id)
.correlate(Release)
.as_scalar()
.scalar_subquery()
.label("all_versions")
)

Expand All @@ -71,7 +71,7 @@ def _project_docs(db, project_name=None):
.join(Classifier, Classifier.id == release_classifiers.c.trove_id)
.filter(Release.id == release_classifiers.c.release_id)
.correlate(Release)
.as_scalar()
.scalar_subquery()
.label("classifiers")
)

Expand Down

0 comments on commit d89d523

Please sign in to comment.