Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various minor improvements before releasing version 3.3.1+ #1087

Merged
merged 6 commits into from
Aug 18, 2024
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
18 changes: 1 addition & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

jobs:
tests:
name: Python ${{ matrix.python-version }}, Database ${{ matrix.database-type }}
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-latest

strategy:
Expand All @@ -26,22 +26,6 @@ jobs:
- "3.12"
- "pypy-3.9"
- "pypy-3.10"
database-type:
- "sqlite"
- "postgres"

services:
mongodb:
image: mongo
ports:
- 27017:27017

postgresdb:
image: postgres:alpine
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: password

steps:
- uses: actions/checkout@v4
Expand Down
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ test:
-b \
-X dev \
-Werror \
-Wdefault:"the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses":DeprecationWarning:distutils: \
-Wdefault:"Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working":DeprecationWarning:: \
-Wdefault:"set_output_charset() is deprecated":DeprecationWarning:: \
-Wdefault:"parameter codeset is deprecated":DeprecationWarning:: \
-Wdefault:"'cgi' is deprecated and slated for removal in Python 3.13":DeprecationWarning:: \
-Wdefault:"datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version.":DeprecationWarning:: \
-Wignore:::mongomock: \
-Wignore:::mongomock.__version__: \
-Wignore:::pkg_resources: \
-m unittest

# DOC: Test the examples
Expand Down
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,9 @@ To test with a specific framework version, you may use a ``tox`` target:

# run tests inside a specific environment (django)
$ tox -e py310-djangomain
$ tox -e py310-djangomain-postgres

# run tests inside a specific environment (alchemy)
$ tox -e py310-alchemy
$ tox -e py310-alchemy-postgres

# run tests inside a specific environment (mongoengine)
$ tox -e py310-mongo
Expand Down
6 changes: 3 additions & 3 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ ChangeLog
*New:*

- Add support for Django 4.2
- Add support for Django 5.0
- Add support for Django 5.1
- Add support for Python 3.12
- :issue:`903`: Add basic typing annotations
- Run the test suite against ``mongomock`` instead of an actual MongoDB server

*Bugfix:*

Expand All @@ -19,8 +20,7 @@ ChangeLog

*Removed:*

- Drop support for Django 4.0
- Stop advertising and verifying support for Django 4.1
- Stop advertising and verifying support for Django 3.2, 4.0, 4.1

3.3.0 (2023-07-19)
------------------
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ kwargs
metaclass
misconfiguration
Mogo
MongoDB
mongoengine
pre
prepend
Expand Down
7 changes: 2 additions & 5 deletions factory/alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ def _check_sqlalchemy_session_persistence(self, meta, value):

@staticmethod
def _check_has_sqlalchemy_session_set(meta, value):
try:
if value and meta.sqlalchemy_session:
raise RuntimeError("Provide either a sqlalchemy_session or a sqlalchemy_session_factory, not both")
except AttributeError:
pass
if value is not None and getattr(meta, "sqlalchemy_session", None) is not None:
raise RuntimeError("Provide either a sqlalchemy_session or a sqlalchemy_session_factory, not both")

def _build_default_options(self):
return super()._build_default_options() + [
Expand Down
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ license = MIT
classifiers =
Development Status :: 5 - Production/Stable
Framework :: Django
Framework :: Django :: 3.2
Framework :: Django :: 4.2
Framework :: Django :: 5.0
Framework :: Django :: 5.1
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Expand Down Expand Up @@ -49,8 +48,8 @@ dev =
mypy
Pillow
SQLAlchemy
sqlalchemy_utils
mongoengine
mongomock
wheel>=0.32.0
tox
zest.releaser[recommended]
Expand Down
25 changes: 1 addition & 24 deletions tests/alchemyapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,11 @@


"""Helpers for testing SQLAlchemy apps."""
import os

from sqlalchemy import Column, Integer, Unicode, create_engine
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker

try:
import psycopg2 # noqa: F401
USING_POSTGRES = True
except ImportError:
try:
# pypy does not support `psycopg2` or `psycopg2-binary`
# This is a package that only gets installed with pypy, and it needs to be
# initialized for it to work properly. It mimic `psycopg2` 1-to-1
from psycopg2cffi import compat
compat.register()
USING_POSTGRES = True
except ImportError:
USING_POSTGRES = False

if USING_POSTGRES:
pg_database = 'alch_' + os.environ.get('POSTGRES_DATABASE', 'factory_boy_test')
pg_user = os.environ.get('POSTGRES_USER', 'postgres')
pg_password = os.environ.get('POSTGRES_PASSWORD', 'password')
pg_host = os.environ.get('POSTGRES_HOST', 'localhost')
pg_port = os.environ.get('POSTGRES_PORT', '5432')
engine_name = f'postgresql+psycopg2://{pg_user}:{pg_password}@{pg_host}:{pg_port}/{pg_database}'
else:
engine_name = 'sqlite://'
engine_name = 'sqlite://'

session = scoped_session(sessionmaker())
engine = create_engine(engine_name)
Expand Down
41 changes: 0 additions & 41 deletions tests/djapp/settings_pg.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/test_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
except ImportError:
raise unittest.SkipTest("sqlalchemy tests disabled.")

from sqlalchemy_utils import create_database, database_exists, drop_database

import factory
from factory.alchemy import SQLAlchemyModelFactory

Expand Down Expand Up @@ -77,17 +75,6 @@ class Meta:
text = factory.Sequence(lambda n: "text%s" % n)


if models.USING_POSTGRES:
# sqlite test database gets created/destroyed automatically, postgres does not.

def setUpModule():
if not database_exists(models.engine.url):
create_database(models.engine.url)

def tearDownModule():
drop_database(models.engine.url)


class TransactionTestCase(unittest.TestCase):
def setUp(self):
models.Base.metadata.create_all(models.engine)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_mongoengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
except ImportError:
raise unittest.SkipTest("mongodb tests disabled.")

import mongomock

import factory
from factory.mongoengine import MongoEngineFactory

Expand Down Expand Up @@ -52,6 +54,7 @@ def setUpClass(cls):
db=cls.db_name,
host=cls.db_host,
port=cls.db_port,
mongo_client_class=mongomock.MongoClient,
# PyMongo>=2.1 requires an explicit read_preference.
read_preference=mongo_rp.ReadPreference.PRIMARY,
# PyMongo>=2.1 has a 20s timeout, use 100ms instead
Expand Down
34 changes: 11 additions & 23 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ envlist =
docs
examples
linkcheck
py{38,39,310,311,312,py39,py310}-sqlite
py{38,39,310,311,py39,py310}-django32-mongo-alchemy-{sqlite,postgres}
py{38,39,310,311,312}-django42-mongo-alchemy-{sqlite,postgres}
py{py39,py310}-django42-mongo-alchemy-sqlite,
# py{py39,py310}-django42-mongo-alchemy-postgres # TODO: Fix me!
py{310,311,312}-django50-mongo-alchemy-{sqlite,postgres}
py310-djangomain-mongo-alchemy-{sqlite,postgres}
py{38,39,310,311,312,py39,py310}
py{38,39,310,311,312}-django42-mongo-alchemy
py{py39,py310}-django42-mongo-alchemy
py{310,311,312}-django51-mongo-alchemy
pypy310-django51-mongo-alchemy
py310-djangomain-mongo-alchemy

[gh-actions]
python =
Expand All @@ -23,32 +22,21 @@ python =
pypy-3.9: pypy39
pypy-3.10: pypy310

[gh-actions:env]
DATABASE_TYPE =
sqlite: sqlite
postgres: postgres

[testenv]
passenv =
MONGO_HOST
POSTGRES_HOST
POSTGRES_DATABASE
deps =
mypy
alchemy: SQLAlchemy
alchemy: sqlalchemy_utils
mongo: mongoengine
django{32,42,50,main}: Pillow
django32: Django>=3.2,<3.3
mongo: mongomock
# mongomock imports pkg_resources, provided by setuptools.
mongo: setuptools>=66.1.1
django{42,51,main}: Pillow
django42: Django>=4.2,<5.0
django50: Django>=5.0,<5.1
django51: Django>=5.1,<5.2
djangomain: https://github.com/django/django/archive/main.tar.gz
py{38,39,310,311,312}-postgres: psycopg2-binary
pypy{39,310}-postgres: psycopg2cffi

setenv =
py: DJANGO_SETTINGS_MODULE=tests.djapp.settings
postgres: DJANGO_SETTINGS_MODULE=tests.djapp.settings_pg

allowlist_externals = make
commands = make test
Expand Down