Skip to content

Commit

Permalink
pull in pyproject template from github.com/arbulu89/pyproject-template
Browse files Browse the repository at this point in the history
  • Loading branch information
krig committed Apr 12, 2019
1 parent 9a7e26f commit 9cf4eb9
Show file tree
Hide file tree
Showing 18 changed files with 722 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
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/*
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Version 0.1.0
- First version of the project.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
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.
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions MANIFEST.in
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/*
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# docs
Use this folder to store all the documentation files
2 changes: 2 additions & 0 deletions img/README.md
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
9 changes: 9 additions & 0 deletions myproject/__init__.py
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"
53 changes: 53 additions & 0 deletions myproject/mymodule.py
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]
29 changes: 29 additions & 0 deletions myproject/utils.py
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)
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
python_files = *_test.py
testpaths = tests
norecursedirs =
Empty file added requirements.txt
Empty file.
84 changes: 84 additions & 0 deletions setup.py
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()
2 changes: 2 additions & 0 deletions support/REAMDE.md
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
47 changes: 47 additions & 0 deletions support/unittest_template.py
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 added tests/__init__.py
Empty file.
97 changes: 97 additions & 0 deletions tests/mymodule_test.py
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')
30 changes: 30 additions & 0 deletions tox.ini
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

0 comments on commit 9cf4eb9

Please sign in to comment.