Skip to content

Commit

Permalink
add collection_data_factory fixture, use it
Browse files Browse the repository at this point in the history
  • Loading branch information
briantist committed Oct 8, 2023
1 parent 8355632 commit 9734879
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 9 additions & 3 deletions tests/unit/models/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
# (c) 2022 Brian Scholer (@briantist)

import pytest
import typing as t

from datetime import datetime, timezone
from functools import partial

from galactory.models import CollectionData


@pytest.fixture
def collection_data(request) -> CollectionData:
def collection_data_factory() -> t.Callable[[], CollectionData]:
values = dict(
collection_info={},
namespace='ns',
Expand All @@ -22,6 +24,10 @@ def collection_data(request) -> CollectionData:
size=0,
version='0.0.0',
)
return partial(CollectionData, **values)


@pytest.fixture
def collection_data(request, collection_data_factory) -> CollectionData:
overrides = getattr(request, 'param', {})
values.update(overrides)
return CollectionData(**values)
return collection_data_factory(**overrides)
14 changes: 3 additions & 11 deletions tests/unit/models/test_collectiongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,11 @@ def test_collectiongroup_dunders(mocker: MockFixture, collection_data: Collectio
spy_get_key.reset_mock()


def test_collectiongroup_delete(mocker: MockFixture, collection_data: CollectionData):
def test_collectiongroup_delete(mocker: MockFixture, collection_data_factory):
spy_del = mocker.spy(CollectionGroup, '__delitem__')

col1 = CollectionData.__new__(CollectionData)
col2 = CollectionData.__new__(CollectionData)

col1.__dict__.update(collection_data.__dict__.copy())
col2.__dict__.update(collection_data.__dict__.copy())

col1.version = '1.2.3'
col1.sha256 = 'A'
col2.version = '2.3.4'
col2.sha256 = 'B'
col1 = collection_data_factory(version='1.2.3', sha256='A')
col2 = collection_data_factory(version='2.3.4', sha256='B')

assert col1 is not col2
assert col1 != col2
Expand Down

0 comments on commit 9734879

Please sign in to comment.