Skip to content
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
12 changes: 6 additions & 6 deletions MPCAutofill/cardpicker/tests/__snapshots__/test_views.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
'CARD': dict({
'Brainstorm': dict({
'canonicalArtist': dict({
'name': 'Artist 102',
'name': 'Artist 0',
}),
'canonicalArtistIsFromVoteOnly': False,
'canonicalArtistSource': 'canonical_card',
Expand Down Expand Up @@ -451,7 +451,7 @@
'cards': list([
dict({
'canonicalArtist': dict({
'name': 'Artist 107',
'name': 'Artist 0',
}),
'canonicalArtistIsFromVoteOnly': False,
'canonicalArtistSource': 'canonical_card',
Expand Down Expand Up @@ -793,7 +793,7 @@
'cards': list([
dict({
'canonicalArtist': dict({
'name': 'Artist 109',
'name': 'Artist 0',
}),
'canonicalArtistIsFromVoteOnly': False,
'canonicalArtistSource': 'canonical_card',
Expand Down Expand Up @@ -2792,7 +2792,7 @@
'cards': list([
dict({
'canonicalArtist': dict({
'name': 'Artist 67',
'name': 'Artist 0',
}),
'canonicalArtistIsFromVoteOnly': False,
'canonicalArtistSource': 'canonical_card',
Expand Down Expand Up @@ -3136,7 +3136,7 @@
'cards': list([
dict({
'canonicalArtist': dict({
'name': 'Artist 66',
'name': 'Artist 0',
}),
'canonicalArtistIsFromVoteOnly': False,
'canonicalArtistSource': 'canonical_card',
Expand Down Expand Up @@ -3579,7 +3579,7 @@
'cards': list([
dict({
'canonicalArtist': dict({
'name': 'Artist 68',
'name': 'Artist 0',
}),
'canonicalArtistIsFromVoteOnly': False,
'canonicalArtistSource': 'canonical_card',
Expand Down
21 changes: 0 additions & 21 deletions MPCAutofill/cardpicker/tests/test_artist_votes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,10 @@
from cardpicker.tests.factories import (
CanonicalArtistFactory,
CanonicalCardFactory,
CanonicalExpansionFactory,
CardArtistVoteFactory,
CardFactory,
SourceFactory,
)

# see test_printing_consensus.py for why this capture-and-restore fixture exists
_SHARED_FACTORIES = [
CardFactory,
SourceFactory,
CanonicalArtistFactory,
CanonicalExpansionFactory,
CanonicalCardFactory,
]


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)


@pytest.fixture(autouse=True)
def _clear_rate_limit_cache():
Expand Down
13 changes: 0 additions & 13 deletions MPCAutofill/cardpicker/tests/test_artist_writein.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
)
from cardpicker.tests.factories import CanonicalArtistFactory, CardFactory

# see test_printing_consensus.py for why this capture-and-restore fixture exists
_SHARED_FACTORIES = [CardFactory, CanonicalArtistFactory]


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)


@pytest.fixture(autouse=True)
def _clear_rate_limit_cache():
Expand Down
31 changes: 4 additions & 27 deletions MPCAutofill/cardpicker/tests/test_card_serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,14 @@
)
from cardpicker.tag_consensus import resolve_and_persist_tag_votes
from cardpicker.tests.factories import (
CanonicalArtistFactory,
CanonicalCardFactory,
CanonicalExpansionFactory,
CardFactory,
CardPrintingTagFactory,
CardTagVoteFactory,
SourceFactory,
TagFactory,
)

# see test_printing_consensus.py for why this capture-and-restore fixture exists
_SHARED_FACTORIES = [
CardFactory,
SourceFactory,
CanonicalArtistFactory,
CanonicalExpansionFactory,
CanonicalCardFactory,
TagFactory,
]


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)


class TestSuggestedCanonicalCard:
def test_none_when_flag_not_set(self, db):
Expand Down Expand Up @@ -497,11 +475,10 @@ class TestPostExploreSearchBulkPayload:
Deliberately self-contained (own `SourceFactory`/`CardFactory` calls, own
`search_index --rebuild` call) rather than reusing `test_views.py`'s shared
`all_sources`/`all_cards`/`populated_database` fixtures or its `Cards`/`Sources` test
constants - this module's own `_preserve_shared_factory_sequences` autouse fixture (see
top of file) keeps these tests from perturbing that file's sequence-dependent snapshot
assertions, and no snapshot assertion is used here at all (explicit field assertions
only), per the "avoid --snapshot-update against a subset" trap documented in
docs/troubleshooting.md.
constants. `test_views.py`'s own snapshot assertions are pinned to a fixed factory-sequence
baseline per test (see that file's `_pin_shared_factory_sequences` fixture), so this module's
use of the same shared factories can't perturb them - and no snapshot assertion is used here
at all (explicit field assertions only) regardless.
"""

@staticmethod
Expand Down
23 changes: 0 additions & 23 deletions MPCAutofill/cardpicker/tests/test_consensus_impact_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
test_purge_machine_votes.py's own header comment.
"""

import pytest

from django.core.management import call_command

from cardpicker.artist_consensus import resolve_and_persist_artist
Expand All @@ -27,34 +25,13 @@
from cardpicker.tests.factories import (
CanonicalArtistFactory,
CanonicalCardFactory,
CanonicalExpansionFactory,
CardArtistVoteFactory,
CardFactory,
CardPrintingTagFactory,
CardTagVoteFactory,
SourceFactory,
TagFactory,
)

# see test_printing_consensus.py for why this capture-and-restore fixture exists
_SHARED_FACTORIES = [
CardFactory,
SourceFactory,
CanonicalArtistFactory,
CanonicalExpansionFactory,
CanonicalCardFactory,
]


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)


class TestComputeConsensusImpactReportZeroWrites:
def test_performs_no_writes_at_all(self, db):
Expand Down
21 changes: 0 additions & 21 deletions MPCAutofill/cardpicker/tests/test_consensus_recompute.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,13 @@
from cardpicker.tests.factories import (
CanonicalArtistFactory,
CanonicalCardFactory,
CanonicalExpansionFactory,
CardArtistVoteFactory,
CardFactory,
CardPrintingTagFactory,
CardTagVoteFactory,
SourceFactory,
TagFactory,
)

# see test_consensus_impact_report.py for why this capture-and-restore fixture exists
_SHARED_FACTORIES = [
CardFactory,
SourceFactory,
CanonicalArtistFactory,
CanonicalExpansionFactory,
CanonicalCardFactory,
]


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)


class TestRunConsensusRecomputeDryRun:
def test_dry_run_performs_no_writes(self, db):
Expand Down
26 changes: 0 additions & 26 deletions MPCAutofill/cardpicker/tests/test_deductive_backfill.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

from cardpicker.deductive_backfill import (
DEDUCTIVE_BACKFILL_ANONYMOUS_ID,
run_backfill,
Expand All @@ -10,37 +8,13 @@
from cardpicker.models import PrintingTagStatus, VoteSource
from cardpicker.printing_consensus import resolve_printing
from cardpicker.tests.factories import (
CanonicalArtistFactory,
CanonicalCardFactory,
CanonicalExpansionFactory,
CanonicalPrintingMetadataFactory,
CardFactory,
CardPrintingTagFactory,
SourceFactory,
)

# `factory.Sequence` counters are process-global - see test_printing_consensus.py's identical
# fixture for the full rationale. Mirrored here since this module uses the same shared factories
# - including SourceFactory/CanonicalArtistFactory, consumed indirectly via CardFactory.source
# and CanonicalCardFactory.artist SubFactories, not just the ones referenced by name above.
_SHARED_FACTORIES = [
CardFactory,
SourceFactory,
CanonicalArtistFactory,
CanonicalExpansionFactory,
CanonicalCardFactory,
]


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)


def _unique_printing(name: str, printings_count: int = 1, **kwargs) -> "CanonicalCardFactory":
printing = CanonicalCardFactory(name=name, **kwargs)
Expand Down
30 changes: 1 addition & 29 deletions MPCAutofill/cardpicker/tests/test_harvest_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,7 @@
import cardpicker.harvest_probe as module
from cardpicker.local_identify_printing_tags import EngineVote, OcrCardResult
from cardpicker.models import CardPrintingTag
from cardpicker.tests.factories import (
CanonicalArtistFactory,
CanonicalCardFactory,
CanonicalExpansionFactory,
CardFactory,
SourceFactory,
)

# See test_local_lands_identify.py's identical fixture for the full rationale -
# factory.Sequence counters are process-global across the whole pytest run. Includes every
# factory CardFactory/CanonicalCardFactory transitively consume via SubFactory (source, artist,
# expansion) - see docs/troubleshooting.md's "5-6 unrelated test snapshots break" entry.
_SHARED_FACTORIES = [
CardFactory,
SourceFactory,
CanonicalArtistFactory,
CanonicalExpansionFactory,
CanonicalCardFactory,
]


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)
from cardpicker.tests.factories import CanonicalCardFactory, CardFactory


class FakeImage:
Expand Down
19 changes: 1 addition & 18 deletions MPCAutofill/cardpicker/tests/test_image_cdn_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,7 @@

import cardpicker.image_cdn_fetch as module
from cardpicker.harvest_fetch_limiter import GoogleFetchLockoutError
from cardpicker.tests.factories import (
CanonicalArtistFactory,
CanonicalExpansionFactory,
CardFactory,
SourceFactory,
)

_SHARED_FACTORIES = [CardFactory, SourceFactory, CanonicalArtistFactory, CanonicalExpansionFactory]


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)
from cardpicker.tests.factories import CardFactory


class TestFetchCardImageLockoutCarveOut:
Expand Down
19 changes: 1 addition & 18 deletions MPCAutofill/cardpicker/tests/test_image_evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,7 @@
from cardpicker.local_ocr import DEFAULT_CROP_BOX, LEGAL_LINE_CROP_BOX
from cardpicker.local_phash import ART_CROP_BOX
from cardpicker.models import CardScanLog, ImageEvidence
from cardpicker.tests.factories import (
CanonicalArtistFactory,
CanonicalExpansionFactory,
CardFactory,
SourceFactory,
)

_SHARED_FACTORIES = [CardFactory, SourceFactory, CanonicalArtistFactory, CanonicalExpansionFactory]
from cardpicker.tests.factories import CardFactory


@dataclass(frozen=True)
Expand Down Expand Up @@ -204,16 +197,6 @@ def _build_card_image(
return img


@pytest.fixture(autouse=True)
def _preserve_shared_factory_sequences():
before = {f: f._meta.next_sequence() for f in _SHARED_FACTORIES}
for f, n in before.items():
f.reset_sequence(n, force=True)
yield
for f, n in before.items():
f.reset_sequence(n, force=True)


class TestExtractCardEvidence:
def test_successful_fetch_marks_fetch_ok_and_records_no_skip(self, db, monkeypatch):
card = CardFactory(content_phash=12345)
Expand Down
Loading
Loading