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

Setup CI #10

Closed
wants to merge 10 commits into from
Closed
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
21 changes: 6 additions & 15 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
name: Quality

on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0' # weekly
on: push

jobs:
build:
name: quality
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade black flake8
- name: Run checks
run: |
make quality
run: make quality
28 changes: 10 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Tests

on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0' # weekly
on: push

jobs:
build:
Expand All @@ -30,25 +26,21 @@ jobs:
strategy:
matrix:
python-version:
- 3.6
- 3.7
- 3.8
- 3.9
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
django:
- django22
- django31
- django32
- django41
- django42
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand Down
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
1.4.2 (unreleased)
------------------

- Nothing changed yet.
- Add support for Django 4.1 & 4.2
- Add support for Python 3.10 & 3.11 & 3.12
- Drop support for Python 3.6 & 3.7
- Drop support for Django 3.1
- Drop support for Django 2.2


1.4.1 (2021-06-24)
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.PHONY: update quality tests clean

update:
pip install -r requirements/dev.txt
pip install -r requirements/tests.txt
pip install -r requirements/quality.txt

quality:
black --check --diff metaset tests
Expand Down
4 changes: 2 additions & 2 deletions metaset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from copy import deepcopy
from itertools import chain, groupby
from pkg_resources import get_distribution
from importlib.metadata import version


__version__ = get_distribution("metaset").version
__version__ = version("metaset")


class MetaSet(dict):
Expand Down
11 changes: 2 additions & 9 deletions metaset/django_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

try:
from django.utils.translation import gettext_lazy

try:
# Django >= 3.1
from django.db import JSONField
from django.forms import JSONField as JSONFormField
except ImportError:
# For Django < 3.1
from django.contrib.postgres.fields import JSONField
from django.contrib.postgres.forms import JSONField as JSONFormField
from django.db.models import JSONField
from django.forms import JSONField as JSONFormField
# avoid import failures for non Django builds.
except ImportError:
JSONField = object
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def read(filename):
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
include_package_data=True,
)
30 changes: 15 additions & 15 deletions tests/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from django.test import TestCase

import pytest

from metaset import MetaSet

from .django_test_app import forms as test_forms
Expand All @@ -17,26 +15,25 @@ def refresh_from_db(obj):

class DjangoTest(TestCase):
def test_save_load(self):
obj = test_models.TestModel.objects.create(value={"a": {1}, "b": {2, 3}})
obj = test_models.TestModel.objects.create(
value={"a": {1}, "b": {2, 3}},
)
obj.full_clean()
obj = refresh_from_db(obj)
assert type(obj.value) == MetaSet, type(obj.value)
assert isinstance(obj.value, MetaSet), type(obj.value)
assert obj.value == MetaSet({"a": {1}, "b": {2, 3}}), obj.value

def test_model_form(self):
obj = test_models.TestModel.objects.create(value={"a": {1}, "b": {2, 3}})
obj = test_models.TestModel.objects.create(
value={"a": {1}, "b": {2, 3}},
)
form = test_forms.TestModelForm(instance=obj)
assert json.loads(form["value"].value()) == {"a": [1], "b": [2, 3]}

def test_query(self):
try:
from django.contrib.postgres.fields import JSONField # noqa: F401
except ImportError:
pytest.skip(
"JSON queries are only available " "for native Django (>=1.9) JSONField"
)

obj = test_models.TestModel.objects.create(value={"a": {1}, "b": {2, 3}})
obj = test_models.TestModel.objects.create(
value={"a": {1}, "b": {2, 3}},
)
res = test_models.TestModel.objects.filter(value__b__contains=[2])
assert obj == res.first(), res
res = test_models.TestModel.objects.filter(value__has_key="a")
Expand All @@ -47,5 +44,8 @@ def test_inception(self):
value={"a": {"b": {1}, "c": {2, 3}}, "d": {"e": {4}}}
)
obj = refresh_from_db(obj)
assert obj.value == MetaSet(a=MetaSet(b={1}, c={2, 3}), d=MetaSet(e={4}))
assert type(obj.value["a"]) == MetaSet, type(obj.value["a"])
assert obj.value == MetaSet(
a=MetaSet(b={1}, c={2, 3}),
d=MetaSet(e={4}),
)
assert isinstance(obj.value["a"], MetaSet), type(obj.value["a"])
9 changes: 4 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
[tox]
envlist =
py{36,37}-django{22,31,32}
py{38,39,nightly}-django{22,31,32,main}
py{38,39,310,311,312,nightly}-django{32,41,42,main}
quality
docstring

[testenv]
commands = pytest --doctest-glob=README.rst --doctest-modules {posargs}
deps =
-rrequirements/tests.txt
django22: Django==2.2.*
django31: Django==3.1.*
django32: Django==3.2.*
django41: Django==4.1.*
django42: Django==4.2.*
djangomain: https://github.com/django/django/archive/refs/heads/main.zip
passenv =
PYTEST_ADDOPTS
Expand All @@ -21,7 +20,7 @@ passenv =
DB_PASSWORD

[testenv:quality]
basepython = python3.9
basepython = python3.12
commands = /usr/bin/make quality
deps =
-rrequirements/quality.txt