diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..8e4ef5f --- /dev/null +++ b/.flake8 @@ -0,0 +1,11 @@ +# Run flake8 (pycodestyle + pyflakes) check. +# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes +# Ignored errors: +# - E501: line too long +# - E265: block comment should start with '# ' (makes it easier to enable/disable code) +# - W503: line break before binary operator (deprecated rule) +# - W505: doc line too long + +[flake8] +ignore = E501,E265,W503,W505 +exclude = .git/,.virtualenv/,__pycache__/,build/,dist/ diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..1f7dec7 --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -0,0 +1,38 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: [3.7, 3.9] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install flake8 + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + python3 setup.py install + - name: Lint code with Python ${{ matrix.python-version }} + run: | + make lint + - name: Test code with Python ${{ matrix.python-version }} + run: | + make test diff --git a/.gitignore b/.gitignore index cace5eb..a17e5c0 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ var/ # Installer logs pip-log.txt pip-delete-this-directory.txt +*.log # Unit test / coverage reports htmlcov/ @@ -47,8 +48,8 @@ coverage.xml *.mo *.pot -# Django stuff: -*.log +# Confs +conf*.json # Sphinx documentation docs/_build/ @@ -56,5 +57,5 @@ docs/_build/ # PyBuilder target/ -#Ipython Notebook +# Ipython Notebook .ipynb_checkpoints diff --git a/Makefile b/Makefile index 012c95e..2d604a3 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,11 @@ PYFILES = mm_client/ examples/ all: -format: - black ${PYFILES} - lint: flake8 ${PYFILES} -develop: - pip install -e .[dev] +test: + python3 -m unittest discover tests/ -v build: clean python setup.py sdist bdist_wheel diff --git a/setup.cfg b/setup.cfg index ab07ec8..089e649 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,8 +20,9 @@ classifiers = Development Status :: 5 - Production/Stable Environment :: Console License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3) - Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 Topic :: Multimedia :: Video Topic :: Software Development :: Libraries :: Python Modules @@ -32,15 +33,13 @@ install_requires = packages = mm_client mm_client.lib -setup_requires= - setuptools +setup_requires = + setuptools >= 30.3.0 wheel [options.extras_require] dev = - black flake8 - twine [bdist_wheel] universal = 1 diff --git a/tests/test_client.py b/tests/test_client.py new file mode 100644 index 0000000..337b13f --- /dev/null +++ b/tests/test_client.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +''' +Miris Manager client test file. +''' +from unittest.mock import patch +import json +import logging +import os +import sys +import unittest +import urllib3 + +CONFIG = { + 'SERVER_URL': 'https://mmctest' +} + + +def mocked_requests_get(*args, **kwargs): + class MockResponse: + def __init__(self, json_data, status_code): + self.text = json.dumps(json_data) + self.json_data = json_data + self.status_code = status_code + + def json(self): + return self.json_data + + if kwargs['url'] == CONFIG['SERVER_URL'] + '/api/': + return MockResponse({'version': '8.0.0'}, 200) + + return MockResponse(None, 404) + + +class MMClientTest(unittest.TestCase): + maxDiff = None + + def setUp(self): + print('\n\033[96m----- %s.%s -----\033[0m' % (self.__class__.__name__, self._testMethodName)) + # Setup logging + logging.basicConfig( + level=logging.DEBUG, + format='%(asctime)s %(name)s %(levelname)s %(message)s', + stream=sys.stdout + ) + urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + # Setup sys path + sys.path.pop(0) # Remove current dir + src_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + sys.path.insert(0, src_dir) + + @patch('requests.get', side_effect=mocked_requests_get) + def test_client(self, mock_get): + from mm_client.client import MirisManagerClient + mmc = MirisManagerClient(local_conf=CONFIG) + response = mmc.api_request('PING') + self.assertTrue(isinstance(response, dict)) + self.assertEqual(response['version'], '8.0.0') + + self.assertEqual(len(mock_get.call_args_list), 1) + + +if __name__ == '__main__': + unittest.main()