forked from SUSE/hanadb_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pull in pyproject template from github.com/arbulu89/pyproject-template
- Loading branch information
Showing
18 changed files
with
722 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/htmlcov | ||
/tests/htmlcov | ||
dist/* | ||
.coverage | ||
.cache | ||
.idea | ||
*.pyc | ||
*.egg-info* | ||
.tox/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Version 0.1.0 | ||
- First version of the project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# How to contribute | ||
|
||
Add here all the information related how to contribute to this project. You should | ||
consider adding the branching model, the code quality policies, the review process, | ||
etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Include useful user documentation | ||
include README.md | ||
include CHANGELOG.md | ||
include LICENSE | ||
include requirements.txt | ||
|
||
# Exclude unitary test files | ||
global-exclude tests/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# docs | ||
Use this folder to store all the documentation files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# img | ||
Use this folder to store all the images of the project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
:author: xarbulu | ||
:organization: SUSE Linux GmbH | ||
:contact: [email protected] | ||
:since: 2018-11-13 | ||
""" | ||
|
||
__version__ = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
:author: xarbulu | ||
:organization: SUSE Linux GmbH | ||
:contact: [email protected] | ||
:since: 2018-11-13 | ||
""" | ||
|
||
import logging | ||
|
||
class MyModule: | ||
""" | ||
Example module to show have to create a new one | ||
""" | ||
|
||
def __init__(self): | ||
self._logger = logging.getLogger(__name__) | ||
self._my_values = [] | ||
|
||
def append_value(self, new_value): | ||
""" | ||
Add a new value to `my_values` list | ||
Args: | ||
new_value (any): New value to append to the list | ||
""" | ||
self._my_values.append(new_value) | ||
|
||
def clean(self): | ||
""" | ||
Clean `my_values` list | ||
""" | ||
self._my_values = [] | ||
self._logger.info('The list now is clean!') | ||
|
||
def show(self): | ||
""" | ||
Show values in `my_values` list | ||
""" | ||
for i, value in enumerate(self._my_values): | ||
self._logger.info('%d: %s', i+1, value) | ||
|
||
def first_value(self): | ||
""" | ||
Returns first value of my_values` list | ||
Returns: | ||
any: First value of my_values` list | ||
Raises: | ||
IndexError: my_values` list is empty | ||
""" | ||
|
||
return self._my_values[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
:author: xarbulu | ||
:organization: SUSE Linux GmbH | ||
:contact: [email protected] | ||
:since: 2018-11-13 | ||
""" | ||
|
||
import logging | ||
|
||
def welcome(name): | ||
""" | ||
Welcome newcomer with a message | ||
Args: | ||
name (str): Newcomer name | ||
""" | ||
|
||
logging.getLogger(__name__).info('Hello %s!', name) | ||
|
||
def farewell(name): | ||
""" | ||
Farewell the newcomer | ||
Args: | ||
name (str): Newcomer name | ||
""" | ||
|
||
logging.getLogger(__name__).info('Farewell %s!', name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[pytest] | ||
python_files = *_test.py | ||
testpaths = tests | ||
norecursedirs = |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
Setup script. | ||
:author: xarbulu | ||
:organization: SUSE Linux GmbH | ||
:contact: [email protected] | ||
:since: 2018-11-13 | ||
""" | ||
|
||
import os | ||
|
||
from setuptools import find_packages | ||
try: | ||
from setuptools import setup | ||
except ImportError: | ||
from distutils.core import setup | ||
|
||
import myproject | ||
|
||
def read(fname): | ||
""" | ||
Utility function to read the README file. README file is used to create | ||
the long description. | ||
""" | ||
|
||
return open(os.path.join(os.path.dirname(__file__), fname)).read() | ||
|
||
VERSION = myproject.__version__ | ||
NAME = "myproject" | ||
DESCRIPTION = "Project template" | ||
|
||
AUTHOR = "xarbulu" | ||
AUTHOR_EMAIL = "[email protected]" | ||
URL = "" | ||
|
||
LICENSE = read('LICENSE') | ||
|
||
CLASSIFIERS = [ | ||
"Development Status :: 4 - Beta", | ||
"Environment :: Console", | ||
"Intended Audience :: Developers", | ||
"License :: Other/Proprietary License", | ||
"Natural Language :: English", | ||
"Operating System :: Unix", | ||
"Operating System :: Microsoft :: Windows", | ||
"Programming Language :: Python :: 2.7", | ||
"Programming Language :: Python :: 2 :: Only", | ||
] | ||
|
||
SCRIPTS = [] | ||
|
||
DEPENDENCIES = read('requirements.txt').split() | ||
|
||
PACKAGE_DATA = {} | ||
DATA_FILES = [] | ||
|
||
|
||
SETUP_PARAMS = dict( | ||
name=NAME, | ||
version=VERSION, | ||
description=DESCRIPTION, | ||
author=AUTHOR, | ||
author_email=AUTHOR_EMAIL, | ||
url=URL, | ||
long_description=read('README.md'), | ||
packages=find_packages(), | ||
package_data=PACKAGE_DATA, | ||
license=LICENSE, | ||
scripts=SCRIPTS, | ||
data_files=DATA_FILES, | ||
install_requires=DEPENDENCIES, | ||
classifiers=CLASSIFIERS, | ||
) | ||
|
||
def main(): | ||
""" | ||
Setup.py main. | ||
""" | ||
|
||
setup(**SETUP_PARAMS) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# support | ||
Use this folder to store all support files, executables, etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Unitary tests for your_module.py. | ||
:author: xarbulu | ||
:organization: SUSE Linux GmbH | ||
:contact: [email protected] | ||
:since: 2018-11-13 | ||
""" | ||
|
||
# pylint:disable=C0103,C0111,W0212,W0611 | ||
|
||
import logging | ||
import unittest | ||
|
||
import mock | ||
|
||
from .. import myproject | ||
|
||
class TestYourClassName(unittest.TestCase): | ||
""" | ||
Unitary tests for YourClassName. | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
""" | ||
Global setUp. | ||
""" | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
def setUp(self): | ||
""" | ||
Test setUp. | ||
""" | ||
|
||
def tearDown(self): | ||
""" | ||
Test tearDown. | ||
""" | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
""" | ||
Global tearDown. | ||
""" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
""" | ||
Unitary tests for mymodule.py. | ||
:author: xarbulu | ||
:organization: SUSE Linux GmbH | ||
:contact: [email protected] | ||
:since: 2018-11-13 | ||
""" | ||
|
||
# pylint:disable=C0103,C0111,W0212,W0611 | ||
|
||
import os | ||
import sys | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
|
||
import logging | ||
import unittest | ||
|
||
import mock | ||
|
||
from myproject import mymodule, utils | ||
|
||
class TestMyModule(unittest.TestCase): | ||
""" | ||
Unitary tests for YourClassName. | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
""" | ||
Global setUp. | ||
""" | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
def setUp(self): | ||
""" | ||
Test setUp. | ||
""" | ||
self._test_module = mymodule.MyModule() | ||
|
||
def tearDown(self): | ||
""" | ||
Test tearDown. | ||
""" | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
""" | ||
Global tearDown. | ||
""" | ||
|
||
def test_append_value(self): | ||
self._test_module.append_value(5) | ||
self.assertEqual(5, self._test_module._my_values[-1]) | ||
|
||
self._test_module.append_value('hello') | ||
self.assertEqual('hello', self._test_module._my_values[-1]) | ||
|
||
def test_clean(self): | ||
self._test_module._my_values.append(5) | ||
self._test_module.clean() | ||
self.assertEqual([], self._test_module._my_values) | ||
|
||
@mock.patch('logging.Logger.info') | ||
def test_show(self, logger): | ||
self._test_module._my_values.append(5) | ||
self._test_module._my_values.append(15) | ||
self._test_module._my_values.append(25) | ||
|
||
self._test_module.show() | ||
|
||
logger.assert_has_calls([ | ||
mock.call('%d: %s', 1, 5), | ||
mock.call('%d: %s', 2, 15), | ||
mock.call('%d: %s', 3, 25) | ||
]) | ||
|
||
def test_first_value(self): | ||
self._test_module._my_values.append(5) | ||
value = self._test_module.first_value() | ||
self.assertEqual(5, value) | ||
|
||
def test_first_value_empty(self): | ||
with self.assertRaises(IndexError): | ||
self._test_module.first_value() | ||
|
||
@mock.patch('logging.Logger.info') | ||
def test_welcome(self, logger): | ||
utils.welcome('xarbulu') | ||
logger.assert_called_once_with("Hello %s!", 'xarbulu') | ||
|
||
@mock.patch('logging.Logger.info') | ||
def test_farewell(self, logger): | ||
utils.farewell('xarbulu') | ||
logger.assert_called_once_with("Farewell %s!", 'xarbulu') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# content of: tox.ini , put in same dir as setup.py | ||
[tox] | ||
envlist = py27,py36 | ||
|
||
[testenv] | ||
changedir=tests | ||
deps = | ||
pylint | ||
pytest | ||
pytest-cov | ||
mock | ||
|
||
commands = | ||
#pylint -f parseable --rcfile=../.pylintrc myproject | ||
py.test -vv --cov=myproject --cov-config ../.coveragerc --cov-report term --cov-report html | ||
|
||
[testenv:coveralls] | ||
passenv = TRAVIS TRAVIS_* | ||
changedir=tests | ||
deps = | ||
pylint | ||
pytest | ||
pytest-cov | ||
mock | ||
coveralls | ||
|
||
commands = | ||
#pylint -f parseable --rcfile=../.pylintrc myproject | ||
py.test -vv --cov=myproject --cov-config ../.coveragerc --cov-report term | ||
coveralls |