From d91ad8b0fd4d62ed709659a5ba5ae1c79d240752 Mon Sep 17 00:00:00 2001 From: Ilya Kulakov Date: Sun, 29 Oct 2017 11:41:41 -0700 Subject: [PATCH] Add travis integration. --- .travis.yml | 33 ++++++++++++++++++ README.md | 9 +++++ requirements.txt | 3 ++ setup.cfg | 3 ++ setup.py | 46 +++++++++++++++++++++----- tests/__init__.py | 0 tests/observer.py | 23 +++++++++++++ power/tests.py => tests/test_common.py | 21 ------------ 8 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 .travis.yml create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 tests/__init__.py create mode 100644 tests/observer.py rename power/tests.py => tests/test_common.py (67%) diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..efda579 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,33 @@ +language: python +sudo: false + +os: + - linux + +python: + - 2.7 + - 3.4 + - 3.5 + - 3.6 + - pypy + - pypy3 + +install: + - pip install .[tests] -c requirements.txt + - pip install codecov flake8 + +script: + - python setup.py test + +after_success: + - flake8 power + - codecov + +deploy: + provider: pypi + user: Ilya.Kulakov + password: + secure: "Lm2m4xqLGyqaSVtsHjyJKAjYxHAe+gB8TSmZZOkmSKfG+g61lAj3mtX8sAXiYzVcsFDe8cX4XvS3i/K2LoOh9dnc9EureDylvtfzjdKfLRqVjHAcHEeGLBck5tfgQXi3zKiB2EE3Pmu2pV+U0UvhpV40PgaFCroMJGJKI8shme8=" + on: + tags: true + branch: master diff --git a/README.md b/README.md index 18177f8..6710854 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,14 @@ Power ===== +.. image:: https://travis-ci.org/Kentzo/Power.svg?branch=master + :target: https://travis-ci.org/Kentzo/Power +.. image:: https://codecov.io/gh/Kentzo/Power/branch/master/graph/badge.svg + :target: https://codecov.io/gh/Kentzo/Power +.. image:: https://img.shields.io/pypi/v/Power.svg + :target: https://pypi.python.org/pypi/Power +.. image:: https://pyup.io/repos/github/Kentzo/Power/shield.svg + :target: https://pyup.io/repos/github/Kentzo/Power/ + :alt: Updates Crossplatform (Windows, Linux, Mac OS X, FreeBSD) python module to access power capabilities of the system. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..913415c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pyobjc-core==4.0; sys_platform == 'darwin' +pytest==3.2.3 +pytest-cov==2.5.1 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..d6cb453 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[tool:pytest] +addopts= --cov=power --cov-report=term-missing --cov-report=html --cov-branch --ignore=setup.py +testpaths=tests diff --git a/setup.py b/setup.py index 3d9fc03..8cec358 100644 --- a/setup.py +++ b/setup.py @@ -1,23 +1,45 @@ #!/usr/bin/env python # coding=utf-8 -__author__ = 'kulakov.ilya@gmail.com' +import sys from setuptools import setup -from sys import platform +from setuptools.command.test import test as TestCommand REQUIREMENTS = [] - -if platform.startswith('darwin'): +if sys.platform.startswith('darwin'): REQUIREMENTS.append('pyobjc-core >= 2.5') +TEST_REQUIREMENTS = [ + 'pytest', + 'pytest-cov', +] + + +class PyTest(TestCommand): + user_options = [('pytest-args=', 'a', "Arguments to pass to pytest")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.pytest_args = '' + + def run_tests(self): + import shlex + #import here, cause outside the eggs aren't loaded + import pytest + errno = pytest.main(shlex.split(self.pytest_args)) + sys.exit(errno) + + setup( name="power", - version="1.4", + version="1.5.dev0", description="Cross-platform system power status information.", - long_description="Library that allows you get current power source type (AC, Battery or UPS), warning level (none, <22%, <10min) and remaining minutes. You can also observe changes of power source and remaining time.", + long_description="Library that allows you get current power source type (AC, Battery or UPS), " + "warning level (none, <22%, <10min) and remaining minutes. " + "You can also observe changes of power source and remaining time.", author="Ilya Kulakov", author_email="kulakov.ilya@gmail.com", url="https://github.com/Kentzo/Power", @@ -32,9 +54,17 @@ 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', 'Topic :: System :: Monitoring', 'Topic :: System :: Power (UPS)', ], - install_requires=REQUIREMENTS + install_requires=REQUIREMENTS, + tests_require=TEST_REQUIREMENTS, + extras_require={ + 'tests': TEST_REQUIREMENTS + }, + cmdclass={'test': PyTest} ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/observer.py b/tests/observer.py new file mode 100644 index 0000000..8c10a48 --- /dev/null +++ b/tests/observer.py @@ -0,0 +1,23 @@ +# coding=utf-8 +import power + + +class TestObserver(power.PowerManagementObserver): + def on_power_sources_change(self, power_management): + print("on_power_sources_change") + + def on_time_remaining_change(self, power_management): + print("on_time_remaining_change") + + +if __name__ == "__main__": + o = TestObserver() + p = power.PowerManagement() + p.add_observer(o) + try: + print("Power management observer is registered") + import time + while True: + time.sleep(1) + finally: + p.remove_observer(o) diff --git a/power/tests.py b/tests/test_common.py similarity index 67% rename from power/tests.py rename to tests/test_common.py index ff76206..fbdbbe6 100644 --- a/power/tests.py +++ b/tests/test_common.py @@ -25,24 +25,3 @@ def testGetProvidingPowerSource(self): self.assertIsNotNone(type) self.assertIsInstance(type, int) self.assertIn(type, [power.POWER_TYPE_AC, power.POWER_TYPE_BATTERY, power.POWER_TYPE_UPS]) - - -class TestObserver(power.PowerManagementObserver): - def on_power_sources_change(self, power_management): - print("on_power_sources_change") - - def on_time_remaining_change(self, power_management): - print("on_time_remaining_change") - - -if __name__ == "__main__": - o = TestObserver() - p = power.PowerManagement() - p.add_observer(o) - try: - print("Power management observer is registered") - import time - while True: - time.sleep(1) - finally: - p.remove_observer(o)