Skip to content

Commit

Permalink
centralize fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
briantist committed Oct 8, 2023
1 parent 548fc0f commit 2769567
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
35 changes: 11 additions & 24 deletions tests/unit/models/test_collectiondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,51 +145,38 @@ def test_collectiondata_compare_versioninfo(
assert (col < ver) == (col.is_prerelease)


def test_collectiondata_compare_othertypes(mocker: MockFixture):
def test_collectiondata_compare_othertypes(mocker: MockFixture, collection_data: CollectionData):
spy_eq = mocker.spy(CollectionData, '__eq__')
spy_lt = mocker.spy(CollectionData, '__lt__')

coldata = CollectionData(
collection_info={},
created_datetime=datetime.now(timezone.utc),
modified_datetime=datetime.now(timezone.utc),
filename='fname',
mime_type='mime',
size=0,
namespace='ns',
name='col',
version='1.2.3',
sha256='a',
)

standin = 5

assert coldata != mocker.sentinel.whatever
spy_eq.assert_called_once_with(coldata, mocker.sentinel.whatever)
assert collection_data != mocker.sentinel.whatever
spy_eq.assert_called_once_with(collection_data, mocker.sentinel.whatever)
assert spy_eq.spy_return is NotImplemented
spy_eq.reset_mock()

assert coldata != standin
spy_eq.assert_called_once_with(coldata, standin)
assert collection_data != standin
spy_eq.assert_called_once_with(collection_data, standin)
assert spy_eq.spy_return is NotImplemented
spy_eq.reset_mock()

assert standin != coldata
spy_eq.assert_called_once_with(coldata, standin)
assert standin != collection_data
spy_eq.assert_called_once_with(collection_data, standin)
assert spy_eq.spy_return is NotImplemented
spy_eq.reset_mock()

rmsg = r"not supported between instances of 'CollectionData' and"

with pytest.raises(TypeError, match=rmsg):
assert not (coldata < standin)
spy_lt.assert_called_once_with(coldata, standin)
assert not (collection_data < standin)
spy_lt.assert_called_once_with(collection_data, standin)
assert spy_lt.spy_return is NotImplemented
spy_lt.reset_mock()

with pytest.raises(TypeError, match=rmsg):
assert not (coldata > standin)
spy_lt.assert_called_once_with(coldata, standin)
assert not (collection_data > standin)
spy_lt.assert_called_once_with(collection_data, standin)
assert spy_lt.spy_return is NotImplemented
spy_lt.reset_mock()

Expand Down
17 changes: 0 additions & 17 deletions tests/unit/models/test_collectiongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,11 @@

import re
from semver import VersionInfo
from datetime import datetime, timezone
from pytest_mock import MockFixture

from galactory.models import CollectionData, CollectionGroup


@pytest.fixture
def collection_data() -> CollectionData:
return CollectionData(
collection_info={},
namespace='ns',
name='name',
created_datetime=datetime.now(timezone.utc),
modified_datetime=datetime.now(timezone.utc),
filename='fake-file',
mime_type='fake-file',
sha256='m-m-m-my-sha-',
size=0,
version='0.0.0',
)


@pytest.mark.parametrize('name', ['collection_name', 'name2'])
@pytest.mark.parametrize('namespace', ['a_namespace', 'ns1'])
def test_collectiongroup_init(namespace, name):
Expand Down

0 comments on commit 2769567

Please sign in to comment.