From de7028a07a1123619199a3db0756ec4f042a1e57 Mon Sep 17 00:00:00 2001 From: "M. Zulqarnain" Date: Fri, 25 Feb 2022 17:39:36 +0500 Subject: [PATCH] Removed Python 2 & PyYAML<5.1 support --- .github/workflows/pypi-publish.yml | 30 ++++++++++++++ .github/workflows/tests.yml | 36 +++++++++++++++++ .gitignore | 4 +- README.rst | 27 +++++++------ flask_fixtures/__init__.py | 3 +- flask_fixtures/loaders.py | 5 +-- setup.py | 63 ++++++++++++++---------------- tox.ini | 8 ++-- 8 files changed, 118 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/pypi-publish.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml new file mode 100644 index 0000000..941c620 --- /dev/null +++ b/.github/workflows/pypi-publish.yml @@ -0,0 +1,30 @@ +name: Publish package to PyPI + +on: + release: + types: [published] + +jobs: + + push: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: setup python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install pip + run: pip install setuptools wheel + + - name: Build package + run: python setup.py sdist bdist_wheel + + - name: Publish to PyPi + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.PYPI_UPLOAD_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..3e79bc6 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,36 @@ +name: Python CI + +on: + push: + branches: [master] + pull_request: + branches: + - '**' + +jobs: + run_tests: + name: Tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04] + python-version: ['3.8', '3.9'] + toxenv: ['py'] + + steps: + - uses: actions/checkout@v2 + - name: setup python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Dependencies + run: | + pip install --upgrade pip + pip install setuptools wheel tox + pip install . + + - name: Run Tests + env: + TOXENV: ${{ matrix.toxenv }} + run: tox -- --hypothesis-profile=ci diff --git a/.gitignore b/.gitignore index ab9d89d..f4bcc8c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ build dist .vscode -venv \ No newline at end of file +venv + +.idea/ diff --git a/README.rst b/README.rst index d10f4e1..5426623 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,6 @@ -Flask-Fixtures +Flask-YAML-Fixtures ============== +A fork of (Flask-Fixtures by Christopher Roach)[https://github.com/croach/FLask-Fixtures] that works with latest version of PyYAML. A simple library that allows you to add database fixtures for your unit tests using nothing but JSON or YAML. @@ -7,12 +8,12 @@ tests using nothing but JSON or YAML. Installation ------------ -Installing Flask-Fixtures is simple, just do a typical pip install like +Installing FLask-YAML-Fixtures is simple, just do a typical pip install like so: :: - pip install flask-fixtures + pip install flask-yaml-fixtures If you are going to use JSON as your data serialization format, you should also consider installing the dateutil package since it will @@ -24,16 +25,16 @@ install command. :: - git clone https://github.com/croach/Flask-Fixtures.git + git clone https://github.com/mzulqarnain1/Flask-YAML-Fixtures.git cd /path/to/flask-fixtures python setup.py install Setup ----- -To setup the library, you simply need to tell Flask-Fixtures where it +To setup the library, you simply need to tell FLask-YAML-Fixtures where it can find the fixtures files for your tests. Fixtures can reside anywhere -on the file system, but by default, Flask-Fixtures looks for these files +on the file system, but by default, FLask-YAML-Fixtures looks for these files in a directory called ``fixtures`` in your app's root directory. To add more directories to the list to be searched, just add an attribute called ``FIXTURES_DIRS`` to your app's config object. This attribute @@ -208,7 +209,7 @@ fixtures. Usage ----- -To use Flask-Fixtures in your unit tests, you'll need to make sure your +To use FLask-YAML-Fixtures in your unit tests, you'll need to make sure your test class inherits from ``FixturesMixin`` and that you've specified a list of fixtures files to load. The sample code below shows how to do each these steps. @@ -216,13 +217,13 @@ each these steps. First, make sure the app that you're testing is initialized with the proper configuration. Then import and initialize the ``FixturesMixin`` class, create a new test class, and inherit from ``FixturesMixin``. Now you just need to -tell Flask-Fixtures which fixtures files to use for your tests. You can do so +tell FLask-YAML-Fixtures which fixtures files to use for your tests. You can do so by setting the ``fixtures`` class variable. Doing so will setup and tear down fixtures between each test. To persist fixtures across tests, i.e., to setup fixtures only when the class is first created and tear them down after all tests have finished executing, you'll need to set the ``persist_fixtures`` variable to True. The ``fixtures`` variable should be set to a list of -strings, each of which is the name of a fixtures file to load. Flask-Fixtures +strings, each of which is the name of a fixtures file to load. FLask-YAML-Fixtures will then search the default fixtures directory followed by each directory in the ``FIXTURES_DIRS`` config variable, in order, for a file matching each name in the list and load each into the test database. @@ -274,14 +275,14 @@ Examples To see the library in action, you can find a simple Flask application and set of unit tests matching the ones in the example above in the ``tests/myapp`` directory. To run these examples yourself, just follow -the directions below for "Contributing to Flask-Fixtures". +the directions below for "Contributing to FLask-YAML-Fixtures". -Contributing to Flask-Fixtures +Contributing to FLask-YAML-Fixtures ------------------------------ -Currently, Flask-Fixtures supports python versions 2.6 and 2.7 and the +Currently, FLask-YAML-Fixtures supports python versions 3.8+ and the py.test, nose, and unittest (included in the python standard library) -libraries. To contribute bug fixes and features to Flask-Fixtures, +libraries. To contribute bug fixes and features to FLask-YAML-Fixtures, you'll need to make sure that any code you contribute does not break any of the existing unit tests in any of these environments. diff --git a/flask_fixtures/__init__.py b/flask_fixtures/__init__.py index d63332e..5b52e6b 100644 --- a/flask_fixtures/__init__.py +++ b/flask_fixtures/__init__.py @@ -18,7 +18,6 @@ from . import loaders from .utils import can_persist_fixtures -import six import importlib from flask import current_app @@ -252,7 +251,7 @@ def child_fn(obj): return default_fn -class FixturesMixin(six.with_metaclass(MetaFixturesMixin, object)): +class FixturesMixin(metaclass=MetaFixturesMixin): fixtures = None app = None diff --git a/flask_fixtures/loaders.py b/flask_fixtures/loaders.py index a8b970b..c7b2f32 100644 --- a/flask_fixtures/loaders.py +++ b/flask_fixtures/loaders.py @@ -14,7 +14,6 @@ import logging from .utils import print_info -import six try: from dateutil.parser import parse as dtparse @@ -45,7 +44,7 @@ def load(self, filename): log = logging.getLogger(__name__) -class FixtureLoader(six.with_metaclass(abc.ABCMeta, object)): +class FixtureLoader(metaclass=abc.ABCMeta): @abc.abstractmethod def load(self): pass @@ -74,7 +73,7 @@ class YAMLLoader(FixtureLoader): def load(self, filename): with open(filename) as fin: - return yaml.load(fin) + return yaml.safe_load(fin) def load(filename): diff --git a/setup.py b/setup.py index 686fec3..0fa90d3 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ """ -Flask-Fixtures +Flask-YAML-Fixtures -------------- A fixtures library for testing Flask apps. @@ -12,55 +12,50 @@ root_dir = os.path.abspath(os.path.dirname(__file__)) -package_dir = os.path.join(root_dir, 'flask_fixtures') +package_dir = os.path.join(root_dir, "flask_fixtures") # Try to get the long description from the README file or the module's # docstring if the README isn't available. try: - README = open(os.path.join(root_dir, 'README.rst')).read() + README = open(os.path.join(root_dir, "README.rst")).read() except: README = __doc__ -install_requires = [ - 'Flask', - 'Flask-SQLAlchemy', - 'six' - ] +install_requires = ["Flask", "Flask-SQLAlchemy", "PyYAML>5.1"] try: import importlib except ImportError: - install_requires.append('importlib') + install_requires.append("importlib") setup( - name='Flask-Fixtures', - version='0.3.8', - url='https://github.com/croach/Flask-Fixtures', - license='MIT License', - author='Christopher Roach', - author_email='vthakr@gmail.com', - maintainer='Christopher Roach', - maintainer_email='vthakr@gmail.com', - description='A simple library for adding database fixtures for unit tests using nothing but JSON or YAML.', + name="Flask-YAML-Fixtures", + version="0.4.0", + url="https://github.com/mzulqarnain1/Flask-Fixtures", + license="MIT License", + author="Muhammad Zulqarnain", + author_email="zulqarnain.mailbox@gmail.com", + maintainer="Muhammad Zulqarnain", + maintainer_email="zulqarnain.mailbox@gmail.com", + description="A simple library for adding database fixtures for unit tests using nothing but JSON or YAML.", long_description=README, - # py_modules=['flask_fixtures'], - # if you would be using a package instead use packages instead - # of py_modules: install_requires=install_requires, - packages=['flask_fixtures'], + packages=["flask_fixtures"], zip_safe=False, include_package_data=True, - platforms='any', - + platforms="any", classifiers=[ - 'Development Status :: 3 - Alpha', - 'Environment :: Web Environment', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: Software Development :: Testing' - ] + "Development Status :: 3 - Alpha", + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Framework :: Flask", + "Topic :: Internet :: WWW/HTTP :: Dynamic Content", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Software Development :: Testing", + ], ) diff --git a/tox.ini b/tox.ini index 6db93bb..8f6a043 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py26,py27}-flask-{pre-app-ctx,post-app-ctx},py36-post-app-ctx +envlist = py{38,39} [testenv] changedir = tests @@ -8,10 +8,8 @@ commands = py.test -s nosetests --nologcapture -s deps = - flask-pre-app-ctx: Flask < 0.9 - flask-pre-app-ctx: Flask-SQLAlchemy < 2.2 - flask-post-app-ctx: Flask >= 0.9 - flask-post-app-ctx: Flask-SQLAlchemy >= 2.2 + Flask >= 0.9 + Flask-SQLAlchemy >= 2.2 discover nose pytest