From c096c4e673fd00a1bb13c0ce28050ed9f957003c Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 11:19:30 +0200 Subject: [PATCH 1/9] Update pytests --- tox.ini | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 2bca0ee..d7522a0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,16 @@ [tox] distshare = {homedir}/.tox/distshare envlist = py27-pytest{43,44,45,46}, - py38-pytest{43,44,45,46,50,51,52,latest}, + py38-pytest{43,44,45,46,50,51,52,53,54,60,latest}, py{35,36,37}-pytestlatest [testenv] commands = pytest --junitxml={envlogdir}/junit-{envname}.xml {posargs:tests} deps = pytestlatest: pytest + pytest60: pytest~=6.0.0 + pytest54: pytest~=5.4.0 + pytest53: pytest~=5.3.0 pytest52: pytest~=5.2.0 pytest51: pytest~=5.1.0 pytest50: pytest~=5.0.0 From c0f450b9e33a482b168b9800302aac32fbe0f123 Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 11:20:46 +0200 Subject: [PATCH 2/9] Add .env3 to the gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1300240..c1b9844 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.rej *.py[cod] /.env +/.env3 *.orig # C extensions From f1235dced02cff6427f22d3d1bc716158e8f6f11 Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 13:09:20 +0200 Subject: [PATCH 3/9] Add pre-commit configuration --- .pre-commit-config.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f59a625 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files From 1c8f63ed70984b9186c3fd07c49bd3d31e40d3d4 Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 13:26:16 +0200 Subject: [PATCH 4/9] Use `black` for linting --- tox.ini | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index d7522a0..daa1bd5 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,7 @@ distshare = {homedir}/.tox/distshare envlist = py27-pytest{43,44,45,46}, py38-pytest{43,44,45,46,50,51,52,53,54,60,latest}, + py38-pytestlatest-linters, py{35,36,37}-pytestlatest [testenv] @@ -21,6 +22,10 @@ deps = -r{toxinidir}/requirements-testing.txt +[testenv:py38-pytestlatest-linters] +deps = black +commands = black --check --verbose setup.py pytest_factoryboy tests + [pytest] -addopts = -vv -l --pep8 +addopts = -vv -l pep8maxlinelength = 120 From 9c985e66bd5f42ed011cb369351e2479fb2f2f11 Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 13:26:52 +0200 Subject: [PATCH 5/9] Remove unused test dependencies --- requirements-testing.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/requirements-testing.txt b/requirements-testing.txt index 21b44d9..e69de29 100644 --- a/requirements-testing.txt +++ b/requirements-testing.txt @@ -1,4 +0,0 @@ -mock -pytest-pep8 -pytest-cov -pytest-cache From 1ae57f3c77fb0471202a71e4411a099b0a26bc4c Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 13:30:05 +0200 Subject: [PATCH 6/9] Configure black --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..632eb80 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[tool.black] +line-length = 120 +target-version = ['py27', 'py35', 'py36', 'py37', 'py38'] From 64198b990e1d9ee47b6b04ccb0bb847582a05195 Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 13:31:44 +0200 Subject: [PATCH 7/9] Apply `black` formatting tool to the codebase --- pytest_factoryboy/__init__.py | 2 +- pytest_factoryboy/fixture.py | 20 +++++++++----------- pytest_factoryboy/plugin.py | 7 ++++--- setup.py | 10 ++++++---- tests/test_circular.py | 4 +--- tests/test_factory_fixtures.py | 2 +- tests/test_postgen_dependencies.py | 11 ++++------- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/pytest_factoryboy/__init__.py b/pytest_factoryboy/__init__.py index bea2cc3..e43d4de 100644 --- a/pytest_factoryboy/__init__.py +++ b/pytest_factoryboy/__init__.py @@ -1,7 +1,7 @@ """pytest-factoryboy public API.""" from .fixture import register, LazyFixture -__version__ = '2.0.3' +__version__ = "2.0.3" __all__ = [ diff --git a/pytest_factoryboy/fixture.py b/pytest_factoryboy/fixture.py index 7b4bdb5..606f440 100644 --- a/pytest_factoryboy/fixture.py +++ b/pytest_factoryboy/fixture.py @@ -144,7 +144,9 @@ def get_model_name(factory_class): """Get model fixture name by factory.""" return ( inflection.underscore(factory_class._meta.model.__name__) - if not isinstance(factory_class._meta.model, str) else factory_class._meta.model) + if not isinstance(factory_class._meta.model, str) + else factory_class._meta.model + ) def get_factory_name(factory_class): @@ -164,7 +166,7 @@ def is_dep(value): if isinstance(value, factory.RelatedFactory): return False if isinstance(value, factory.SubFactory) and get_model_name(value.get_factory()) == parent_model_name: - return False + return False if isinstance(value, factory.declarations.PostGeneration): # Dependency on extracted value return True @@ -172,9 +174,7 @@ def is_dep(value): return True return [ - SEPARATOR.join((model_name, attr)) - for attr, value in factory_class._meta.declarations.items() - if is_dep(value) + SEPARATOR.join((model_name, attr)) for attr, value in factory_class._meta.declarations.items() if is_dep(value) ] @@ -199,7 +199,8 @@ class Factory(factory_class): pass Factory._meta.base_declarations = dict( - (k, v) for k, v in Factory._meta.base_declarations.items() + (k, v) + for k, v in Factory._meta.base_declarations.items() if not isinstance(v, factory.declarations.PostGenerationDeclaration) ) Factory._meta.post_declarations = factory.builder.DeclarationSet() @@ -233,7 +234,7 @@ class Factory(factory_class): argname = "".join((prefix, attr)) extra = {} for k, v in factory_class._meta.post_declarations.contexts[attr].items(): - if k == '': + if k == "": continue post_attr = SEPARATOR.join((argname, k)) @@ -339,10 +340,7 @@ def __init__(self, fixture): self.fixture = fixture if callable(self.fixture): params = signature(self.fixture).parameters.values() - self.args = [ - param.name for param in params - if param.kind == param.POSITIONAL_OR_KEYWORD - ] + self.args = [param.name for param in params if param.kind == param.POSITIONAL_OR_KEYWORD] else: self.args = [self.fixture] diff --git a/pytest_factoryboy/plugin.py b/pytest_factoryboy/plugin.py index fb143cc..60f4048 100644 --- a/pytest_factoryboy/plugin.py +++ b/pytest_factoryboy/plugin.py @@ -27,11 +27,11 @@ def defer(self, functions): self.deferred.append(functions) def get_deps(self, request, fixture, deps=None): - request = request.getfixturevalue('request') + request = request.getfixturevalue("request") if deps is None: deps = set([fixture]) - if fixture == 'request': + if fixture == "request": return deps for fixturedef in request._fixturemanager.getfixturedefs(fixture, request._pyfuncitem.parent.nodeid) or []: @@ -43,7 +43,7 @@ def get_deps(self, request, fixture, deps=None): def get_current_deps(self, request): deps = set() - while hasattr(request, '_parent_request'): + while hasattr(request, "_parent_request"): if request.fixturename and request.fixturename not in getattr(request, "_fixturedefs", {}): deps.add(request.fixturename) request = request._parent_request @@ -113,6 +113,7 @@ def pytest_runtest_call(item): def pytest_addhooks(pluginmanager): """Register plugin hooks.""" from pytest_factoryboy import hooks + pluginmanager.add_hookspecs(hooks) diff --git a/setup.py b/setup.py index 7d819e6..0ab561e 100755 --- a/setup.py +++ b/setup.py @@ -9,12 +9,14 @@ dirname = os.path.dirname(__file__) long_description = ( - codecs.open(os.path.join(dirname, "README.rst"), encoding="utf-8").read() + "\n" + - codecs.open(os.path.join(dirname, "AUTHORS.rst"), encoding="utf-8").read() + "\n" + - codecs.open(os.path.join(dirname, "CHANGES.rst"), encoding="utf-8").read() + codecs.open(os.path.join(dirname, "README.rst"), encoding="utf-8").read() + + "\n" + + codecs.open(os.path.join(dirname, "AUTHORS.rst"), encoding="utf-8").read() + + "\n" + + codecs.open(os.path.join(dirname, "CHANGES.rst"), encoding="utf-8").read() ) -with codecs.open(os.path.join(dirname, 'pytest_factoryboy', '__init__.py'), encoding='utf-8') as fd: +with codecs.open(os.path.join(dirname, "pytest_factoryboy", "__init__.py"), encoding="utf-8") as fd: VERSION = re.compile(r".*__version__ = '(.*?)'", re.S).match(fd.read()).group(1) setup( diff --git a/tests/test_circular.py b/tests/test_circular.py index daf2055..f42f8c6 100644 --- a/tests/test_circular.py +++ b/tests/test_circular.py @@ -28,17 +28,15 @@ def __init__(self, name): class AuthorFactory(factory.Factory): - class Meta: model = Author name = "Charles Dickens" - book = factory.RelatedFactory('tests.test_circular.BookFactory', 'author') + book = factory.RelatedFactory("tests.test_circular.BookFactory", "author") class BookFactory(factory.Factory): - class Meta: model = Book diff --git a/tests/test_factory_fixtures.py b/tests/test_factory_fixtures.py index 439d6c7..cb3177f 100644 --- a/tests/test_factory_fixtures.py +++ b/tests/test_factory_fixtures.py @@ -184,7 +184,7 @@ def test_lazy_fixture_callable(book, another_author): ("author__register_user", "author__register_user__password"), [ (LazyFixture(lambda: "lazyfixture"), LazyFixture(lambda: "asdasd")), - ] + ], ) def test_lazy_fixture_post_generation(author): """Test that post-generation values are replaced with lazy fixtures.""" diff --git a/tests/test_postgen_dependencies.py b/tests/test_postgen_dependencies.py index 87c6916..b54d2a8 100644 --- a/tests/test_postgen_dependencies.py +++ b/tests/test_postgen_dependencies.py @@ -7,14 +7,12 @@ class Foo(object): - def __init__(self, value, expected): self.value = value self.expected = expected class Bar(object): - def __init__(self, foo): self.foo = foo @@ -66,8 +64,8 @@ def test_postgen_invoked(foo): register(BarFactory) -@pytest.mark.parametrize('foo__value', [3]) -@pytest.mark.parametrize('foo__expected', [1]) +@pytest.mark.parametrize("foo__value", [3]) +@pytest.mark.parametrize("foo__expected", [1]) def test_depends_on(bar): """Test that post-generation hooks are done and the value is 1.""" assert bar.foo.value == 1 @@ -75,14 +73,14 @@ def test_depends_on(bar): def test_getfixturevalue(request, factoryboy_request): """Test post-generation declarations via the getfixturevalue.""" - foo = request.getfixturevalue('foo') + foo = request.getfixturevalue("foo") assert not factoryboy_request.deferred assert foo.value == 1 def test_after_postgeneration(foo): """Test _after_postgeneration is called.""" - assert foo._postgeneration_results == {'set1': None} + assert foo._postgeneration_results == {"set1": None} assert foo._create is True @@ -92,7 +90,6 @@ class Ordered(object): @register class OrderedFactory(factory.Factory): - class Meta: model = Ordered From cd113b05ccf6c13e4c32b4631bbb0c7a48d3ca9c Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 13:34:03 +0200 Subject: [PATCH 8/9] Fix version discovery --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0ab561e..c7006f4 100755 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ ) with codecs.open(os.path.join(dirname, "pytest_factoryboy", "__init__.py"), encoding="utf-8") as fd: - VERSION = re.compile(r".*__version__ = '(.*?)'", re.S).match(fd.read()).group(1) + VERSION = re.compile(r'.*__version__ = "(.*?)"', re.S).match(fd.read()).group(1) setup( name="pytest-factoryboy", From be9ba281975f6b64ce92605bb1fcbd9add534121 Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 6 Sep 2020 13:41:57 +0200 Subject: [PATCH 9/9] Delete test module that never run a test --- tests/test_attributes_field.py | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 tests/test_attributes_field.py diff --git a/tests/test_attributes_field.py b/tests/test_attributes_field.py deleted file mode 100644 index d8986c1..0000000 --- a/tests/test_attributes_field.py +++ /dev/null @@ -1,30 +0,0 @@ -from pytest_factoryboy import register -import factory - -import pytest - - -class EmptyModel(object): - pass - - -class AttributesFactory(factory.Factory): - class Meta: - model = EmptyModel - - attributes = None - - -register(AttributesFactory, "with_attributes") - - -@pytest.mark.skip(reason="Doesn't work in FactoryBoy at the moment") -def test_factory_with_attributes(): - """Test that a factory can have a `attributes` field when used as a factory.""" - AttributesFactory() - - -@pytest.mark.skip(reason="Doesn't work in FactoryBoy at the moment") -def test_factory_fixture_with_attributes(with_attributes): - """Test that a factory can have a `attributes` field when used as a fixture.""" - pass