Skip to content

Commit

Permalink
Merge b452875 into 63c9d25
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Smith committed Aug 13, 2021
2 parents 63c9d25 + b452875 commit 5b2eece
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 24 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
@@ -0,0 +1,44 @@
name: Tests

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6,3.7,3.8]
steps:
- uses: actions/checkout@v1
- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
coverage:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v1
- name: Setup python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox -e coverage
- name: Coveralls
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,8 @@
/build/
/dist/
/*.egg-info/
/.idea
/venv
/.tox
.coverage
lcov.info
7 changes: 7 additions & 0 deletions CHANGES
Expand Up @@ -2,6 +2,13 @@
CHANGELOG
=========

2.0.0 (unreleased)
==================

- Dropped support for python 2
- Dropped support for Django <2
- Moved testing to GitHub Actions and tox

1.0.1 (unreleased)
==================

Expand Down
5 changes: 3 additions & 2 deletions README.rst
@@ -1,8 +1,9 @@

*django-sizefield* is a file size field, stored as BigInteger and rendered
with units in Bytes (KB, MB, ...)

.. image:: https://travis-ci.org/leplatrem/django-sizefield.png
:target: https://travis-ci.org/leplatrem/django-sizefield
.. image:: https://github.com/leplatrem/django-sizefield/actions/workflows/tests.yml/badge.svg
:target: https://github.com/leplatrem/django-sizefield/actions/workflows/tests.yml

.. image:: https://coveralls.io/repos/leplatrem/django-sizefield/badge.png
:target: https://coveralls.io/r/leplatrem/django-sizefield
Expand Down
21 changes: 6 additions & 15 deletions quicktest.py
Expand Up @@ -16,12 +16,6 @@ class QuickDjangoTest(object):
http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app
"""
DIRNAME = os.path.dirname(__file__)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
)

def __init__(self, *args, **kwargs):
self.apps = args
Expand All @@ -42,22 +36,19 @@ def run_tests(self):
'PORT': '',
}
},
INSTALLED_APPS=self.INSTALLED_APPS + self.apps,
INSTALLED_APPS= self.apps,
)

if django.VERSION >= (1, 7, 0):
# see: https://docs.djangoproject.com/en/dev/releases/1.7/#standalone-scripts
django.setup()
if django.VERSION >= (1, 6, 0):
# see: https://docs.djangoproject.com/en/dev/releases/1.6/#discovery-of-tests-in-any-test-module
from django.test.runner import DiscoverRunner as Runner
else:
from django.test.simple import DjangoTestSuiteRunner as Runner
# Setup configuration
django.setup()

from django.test.runner import DiscoverRunner as Runner

failures = Runner().run_tests(self.apps, verbosity=1)
if failures: # pragma: no cover
sys.exit(failures)


if __name__ == '__main__':
"""
What do when the user hits this file from the shell.
Expand Down
12 changes: 10 additions & 2 deletions setup.py
Expand Up @@ -6,7 +6,7 @@

setup(
name='django-sizefield',
version='1.0.1.dev0',
version='2.0.0',
author='Mathieu Leplatre',
author_email='contact@mathieu-leplatre.info',
url='https://github.com/leplatrem/django-sizefield',
Expand All @@ -18,6 +18,10 @@
install_requires=[
'Django',
],
tests_require=[
'tox'
],
python_requires='>=3.5',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
Expand All @@ -28,5 +32,9 @@
'Environment :: Web Environment',
'Framework :: Django',
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2.7'],
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
)
5 changes: 3 additions & 2 deletions sizefield/models.py
Expand Up @@ -7,7 +7,6 @@


class FileSizeField(models.BigIntegerField):

default_error_messages = {
'invalid': _(u'Incorrect file size format.'),
}
Expand All @@ -25,8 +24,10 @@ def to_python(self, value):
except ValueError:
raise exceptions.ValidationError(self.error_messages['invalid'])


try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^sizefield\.models\.FileSizeField"])

add_introspection_rules([], [r"^sizefield\.models\.FileSizeField"])
except ImportError:
pass
5 changes: 2 additions & 3 deletions sizefield/utils.py
Expand Up @@ -5,7 +5,6 @@
import operator

from django.utils import formats
from django.utils import six
from django.utils.translation import ugettext as _
from django.conf import settings

Expand Down Expand Up @@ -44,7 +43,7 @@ def filesizeformat(bytes, decimals=1):
def filesize_number_format(value):
return formats.number_format(round(value, decimals), decimals)

units_list = sorted(six.iteritems(FILESIZE_UNITS), key=operator.itemgetter(1))
units_list = sorted(FILESIZE_UNITS.items(), key=operator.itemgetter(1))

value = unit = None
len_unints_list = len(units_list)
Expand All @@ -66,7 +65,7 @@ def parse_size(size):
"""
@rtype int
"""
if isinstance(size, six.integer_types):
if isinstance(size, int):
return size

r = file_size_re.match(size.strip())
Expand Down
36 changes: 36 additions & 0 deletions tox.ini
@@ -0,0 +1,36 @@
[tox]
envlist = py{36,37,38}-django{22,30,31,32}, flake8, coverage

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38, flake8

[testenv:flake8]
setenv =
PYTHONPATH = {toxinidir}
deps = flake8
commands= flake8 --ignore=E501 sizefield

[testenv:coverage]
setenv =
PYTHONPATH = {toxinidir}
deps =
coveralls
coveragepy-lcov
commands =
coverage run quicktest.py sizefield
coveragepy-lcov


[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
django22: django>=2.2,<2.3
django30: django>=3.0,<3.1
django31: django>=3.1,<3.2
django32: django>=3.2,<3.3
commands =
python quicktest.py sizefield

0 comments on commit 5b2eece

Please sign in to comment.