Skip to content

Commit

Permalink
infra: use hatch
Browse files Browse the repository at this point in the history
  • Loading branch information
cybergrind committed Feb 5, 2024
1 parent 02e3a53 commit 64ba5fd
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 99 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
max_line_length = 100

[**.py]
indent_style = space
indent_size = 4
emacs_py_project = .
emacs_py_formatter = ruff

[Makefile]
indent_style = tab
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ wheelhouse/
.tox
*~
htmlcov
/.envrc
1 change: 1 addition & 0 deletions .projectile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-/venv
13 changes: 13 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
extends: default

rules:
line-length:
max: 100
level: warning

truthy:
allowed-values: ['true', 'false', 'yes', 'no']

indentation:
indent-sequences: whatever
110 changes: 93 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,94 @@
[tool.black]
[project]
name = 'pytest-tipsi-django'
dynamic = ["version"]
description = 'Better fixtures for django'
readme = "README.rst"
authors = [
{ name = 'cybergrind', email = '[email protected]' }
]
keywords = ['pytest', 'pytest-django', 'fixtures', 'transactions', 'scopes']
dependencies = [
'django',
'pytest>=6.0.0',
'pytest-django>=3.10',
'fan-tools>=2.8.1',
'pytest-tipsi-testing>=1.4.3',

]
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
'Topic :: Utilities',
]

[project.urls]
github = 'https://github.com/tipsi/pytest-tipsi-django'

[project.optional-dependencies]
test = ['coverage', 'pytests']

[tool.hatch.version]
path = "pytest_tipsi_django/__init__.py"

[build-system]
requires = ['setuptools', 'wheel', 'hatchling']
build-backend = 'hatchling.build'

[tool.hatch.build]
exclude = [
'.*',
'.gitignore',
'tox.ini',
'tests',
'test_django_plugin',
'conftest.py',
'Makefile',
]

[tool.hatch.commands]
prerelease = 'hatch build'

[project.entry-points.pytest11]
pytest_tipsi_django = 'pytest_tipsi_django.plugin'


[tool.ruff]
line-length = 100
skip-string-normalization = true
py36 = true
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''
select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"G", # flake8-logging-format
"ASYNC", # flake8-async
"PIE", # flake8-pie
"T20", # flake8-print
"PT", # flake8-pytest-style
"Q", # flake8-quotes
]
ignore = [
"Q001",
"Q003"
]

[tool.ruff.format]
quote-style = "single"

[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ['snapshot_manager']
lines-after-imports = 2

[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"
inline-quotes = "single"
multiline-quotes = "single"
2 changes: 1 addition & 1 deletion pytest_tipsi_django/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.7.0'
__version__ = '2.8.0'
37 changes: 24 additions & 13 deletions pytest_tipsi_django/django_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import inspect
from contextlib import contextmanager
import warnings
from contextlib import contextmanager

import pytest
from _pytest import fixtures
from pytest_django._version import __version_tuple__
from pytest_django.fixtures import SettingsWrapper as OriginalSettingsWrapper


_transactions_stack = []


Expand All @@ -21,12 +23,14 @@ def get_defs_by_name(vprint, request, name):
defs = fixturemanager._arg2fixturedefs[name]
vprint(
'Get fixtures without respecting factories: {} {}'.format(request.node.nodeid, defs),
level=2)
level=2,
)

# We need this only to finish fixtures in _transactions_stack
# if we have no defs here - there will be infinite loop in atomic_rollback:while below
assert defs, 'Cannot find: {} Available: {}'.format(
name, list(fixturemanager._arg2fixturedefs.keys()))
name, list(fixturemanager._arg2fixturedefs.keys())
)
vprint('Finish variants: {} For: {}'.format(defs, name), level=3)
return defs

Expand Down Expand Up @@ -92,7 +96,7 @@ def module_transaction(request, vprint, django_db_blocker, django_db_setup):
connection.close()


@pytest.fixture
@pytest.fixture()
def function_fixture(request, module_transaction):
warnings.warn('function_fixture is deprecated', DeprecationWarning)
with module_transaction(request.fixturename):
Expand All @@ -106,15 +110,22 @@ def module_fixture(request, module_transaction):
yield


class SettingsWrapper(OriginalSettingsWrapper):
"""
we need `_to_restore` to be object local to work with nesting
see test_settings.py for test case
"""
if __version_tuple__ < (4, 8, 0):

class SettingsWrapper(OriginalSettingsWrapper):
"""
we need `_to_restore` to be object local to work with nesting
see test_settings.py for test case
"""

def __init__(self):
self.__dict__['_to_restore'] = []
assert id(SettingsWrapper._to_restore) != id(self._to_restore)

else:

def __init__(self):
self.__dict__['_to_restore'] = []
assert id(SettingsWrapper._to_restore) != id(self._to_restore)
class SettingsWrapper(OriginalSettingsWrapper):
pass


@pytest.fixture(scope='session')
Expand Down Expand Up @@ -169,7 +180,7 @@ def _inner(request):
function_fx = transaction_fx('function')


@pytest.fixture
@pytest.fixture()
def debug_db_queries():
from django.db import connection
from django.test.utils import CaptureQueriesContext
Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

60 changes: 0 additions & 60 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion test_django_plugin/app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from contextlib import suppress
import pytest
from fan_tools.unix import wait_socket, succ
from fan_tools.unix import wait_socket, succ, ExecError


def create_database():
Expand Down
14 changes: 8 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tox]
envlist =
py310,
py39,
py38

Expand All @@ -11,22 +12,23 @@ passenv = *
deps =
py37: git+https://github.com/yaml/pyyaml.git
coverage
pytest==6.2.*
pytest~=7.4.3
pytest-cov
pytest-django==4.*
psycopg2
pytest-tipsi-testing>=1.3.1
py38: pytest-django~=4.7.0
py39: pytest-django~=4.7.0
py310: pytest-django~=4.8.0
psycopg2-binary
pytest-tipsi-testing>=1.4.3
ipdb
six

commands =
python setup.py --quiet clean develop
pytest --cov --ds=test_django_plugin.settings {posargs}
coverage report -m


[testenv:custom-py38]
commands =
python setup.py --quiet clean develop
python -c 'from test_django_plugin.app import apps; print(apps.AppConfig.name)'
pytest --cov --ds=test_django_plugin.settings --reuse-db {posargs}
coverage report -m

0 comments on commit 64ba5fd

Please sign in to comment.