Skip to content

Commit

Permalink
Attempt to add Travis and make installable
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebrennan committed Feb 24, 2020
1 parent a1bd575 commit 5070002
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length=120
ignore: E301, E302, E401, E261, E265, E226, F401, E501
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python
python:
- '3.6'
install:
- make develop
script:
- make test
deploy:
provider: pypi
on:
tags: true
user: jessebrennan
password:
'foo'
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include README.md VERSION release.py
include *.txt
recursive-include src
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
MODULES=src test

all: test

lint:
flake8 $(MODULES)

check_readme:
python setup.py check -r -s

tests:=$(wildcard test/test_*.py)

# A pattern rule that runs a single test module, for example:
# make tests/test_gen3_input_json.py

$(tests): %.py : mypy lint check_readme
python -m unittest --verbose $*.py

test: $(tests)

develop:
pip install -e .
pip install -r requirements.dev.txt

undevelop:
python setup.py develop --uninstall
pip uninstall -y -r requirements.dev.txt

release: test
python release.py $(VERSION)

.PHONY: all lint mypy test develop undevelop release
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
64 changes: 64 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
import re
import sys

#
# a basic release automation script
#
# This should only be called from the Makefile
#

VERSION_FILE = 'VERSION'

help_message = ("The argument must be formatted as either 'major', 'minor', 'patch' or 'X.X.X'\n"
"\n"
"If one of the first three options is used than that part of the version will\n"
"be incremented and all lesser parts of the version will be reset to 0.")


def read_version():
with open(VERSION_FILE, 'r') as fp:
return tuple(map(int, fp.read().split('.')))


def write_version(major, minor, patch):
with open(VERSION_FILE, 'w') as fp:
fp.write(f'{major}.{minor}.{patch}')


def main():
# when called from the makefile we expect only 1 arg
assert len(sys.argv) == 2

arg = sys.argv[1]

major, minor, patch = read_version()
print(f'Previous version set to {major}.{minor}.{patch}')

if arg == 'help':
print(help_message, file=sys.stderr)
exit(0)
elif arg == 'major':
major += 1
minor = 0
patch = 0
elif arg == 'minor':
minor += 1
patch = 0
elif arg == 'patch':
patch += 1
# of form X.X.X
elif re.match('^\d*\.\d*\.\d*$', arg):
major, minor, patch = tuple(arg.split('.'))
else:
print(help_message, file=sys.stderr)
exit(1)

write_version(major, minor, patch)
print(f'New version successfully set to {major}.{minor}.{patch}. To finish release, commit\n'
'changes. Then create a release on github with this version number. Travis will\n'
'automatically upload to PyPI')


if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flake8
ipython
docutils
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
40 changes: 40 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from setuptools import setup, find_packages
from os import path

from release import read_version

here = path.abspath(path.dirname(__file__))

# Get the long description from the README file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()


setup(
name='cutest',
version='{}.{}.{}'.format(*read_version()),
description='A cute, composable unit test framework for Python',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/jessebrennan/cutest',
author='jessebrennan',
author_email='brennan@pacific.net',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'Topic :: Software Development :: Testing',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
package_dir={'': 'src'},
packages=find_packages(where='src'),
python_requires='>=3.6, <4',
install_requires=[],
entry_points={ # Optional
'console_scripts': [
'cutest=cutest:main',
],
},
)
28 changes: 25 additions & 3 deletions src/cutest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import importlib
import inspect
import logging
import sys
from abc import ABC
from concurrent.futures import Executor
from contextlib import contextmanager
Expand Down Expand Up @@ -95,8 +97,11 @@ def prune_all_but(self, nodes: Iterable['Node']) -> bool:
self.children = save_children
return self in nodes or any(save_children)

def __eq__(self, other: 'Node'):
return self.data == other.data
def __eq__(self, other: object) -> bool:
if not isinstance(other, Node):
return NotImplemented
else:
return self.data == other.data

def __hash__(self):
return hash(self.data)
Expand Down Expand Up @@ -392,11 +397,28 @@ def add_tests(self, test_ids: List[str]):
obj.model.initialize()
self.tests += obj.calls
else:
models = [obj for obj in vars(module) if isinstance(obj, Model)]
models: List[Model] = [obj for obj in vars(module) if isinstance(obj, Model)]
for model in models:
model.initialize()
self.models.append(model)


class CutestError(Exception):
pass


def main(argv=None):
if not argv:
# If called programmatically (i.e. tests), we don't want to override logging info
logging.basicConfig(level=logging.INFO)
argv = sys.argv[1:]

parser = argparse.ArgumentParser(description='Run unit tests with cutest')
parser.add_argument('--verbose', '-v', action='count', default=0)
parser.add_argument('tests', nargs='*',
help='a list of any number of test modules, suites, and test methods')
options = parser.parse_args(argv)
collection = Collection()
collection.add_tests(options.tests)
runner = Runner()
runner.run_collection(collection)
15 changes: 1 addition & 14 deletions src/cutest/__main__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import argparse
import sys

from cutest import Collection, Runner


def main(argv):
parser = argparse.ArgumentParser(description='Run unit tests with cutest')
parser.add_argument('--verbose', '-v', action='count', default=0)
parser.add_argument('tests', nargs='*',
help='a list of any number of test modules, suites, and test methods')
options = parser.parse_args(argv)
collection = Collection()
collection.add_tests(options.tests)
runner = Runner()
runner.run_collection(collection)
from cutest import main


if __name__ == '__main__':
Expand Down
1 change: 0 additions & 1 deletion test/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def fix_method(self):
print('fix_2 method')

3 changes: 1 addition & 2 deletions test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ def test_prune(self):
runner = cutest.Runner()
sample.my_suite.initialize()
pruned = list(runner.pruned_suites(sample.test_1.calls))
foo = 1

self.assertEqual(len(pruned), 1)

0 comments on commit 5070002

Please sign in to comment.