diff --git a/.gitignore b/.gitignore index b7422ed2..fc8b0245 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,12 @@ build/ dist/ *egg*/ docs/_build +.coverage +.idea/ +bin/ +include/ +lib/ +local/ +pip-selfcheck.json +src/ +venv/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..b004d9ea --- /dev/null +++ b/.travis.yml @@ -0,0 +1,38 @@ +language: python +dist: trusty + +python: + - "2.7" + +sudo: required + +cache: + pip: true + +addons: + apt: + packages: + - libxml2-dev + - libxmlsec1-dev + - python-dev + - libffi-dev + - libxslt1-dev + - libssl-dev + - libxmlsec1-dev + +env: + - LINT="1" FLAKE="0" TEST="0" + - LINT="0" FLAKE="1" TEST="0" + - LINT="0" FLAKE="0" TEST="1" + +before_install: + - sudo locale-gen en_US en_US.UTF-8 pt_BR.UTF-8 + - sudo dpkg-reconfigure locales + +install: + - virtualenv . + - bin/pip install -r requirements.txt + - bin/pip install -r test-requirements.txt + +script: + - sh travis_run_script.sh diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..5035ef3c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +-e git://github.com/odoo-brazil/pyxmlsec.git@master#egg=pyxmlsec +-e git://github.com/odoo-brazil/geraldo.git@master#egg=geraldo +-e git://github.com/odoo-brazil/libxml2.git@master#egg=libxml2 +lxml +pytz diff --git a/setup.py b/setup.py index 401d8f74..417c914b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ version = "0.1.2", author = "Aristides Caldeira", author_email = 'aristides.caldeira@tauga.com.br', - test_suite='tests', + test_suite='test', keywords = ['nfe', 'nfse', 'cte', 'sped', 'edf', 'ecd'], classifiers=[ 'Development Status :: 4 - Beta', @@ -46,10 +46,12 @@ description = 'PySPED is a library to implement all requirements of the public system of bookkeeping digital', long_description = open('README.rst').read(), install_requires=[ - 'Geraldo >= 0.4.16', - 'PyXMLSec >= 0.3.0' + # List of dependencies is moved to requirements.txt + ], + setup_requires=[ + "flake8" ], tests_require=[ - 'pyflakes>=0.6.1', + # List of dependencies is moved to test-requirements.txt ], ) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000..7dcf7265 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +flake8 +setuptools-lint +coveralls \ No newline at end of file diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 00000000..40a96afc --- /dev/null +++ b/test/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/test/empty_test.py b/test/empty_test.py new file mode 100644 index 00000000..d1775cb8 --- /dev/null +++ b/test/empty_test.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- + +from unittest import TestCase + +class TestEmpty(TestCase): + + def setUp(self): + pass + + def test_empty_01(self): + pass \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/compat.py b/tests/compat.py deleted file mode 100644 index 082efed9..00000000 --- a/tests/compat.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -import unittest - - -def _skipIf(check, message=''): - def _deco(meth): - if check: - return lambda *a, **kw: None - else: - return meth - return _deco - -if hasattr(unittest, 'skipIf'): - skipIf = unittest.skipIf -else: - skipIf = _skipIf diff --git a/tests/test_pyflakes.py b/tests/test_pyflakes.py deleted file mode 100644 index 9fe80d2f..00000000 --- a/tests/test_pyflakes.py +++ /dev/null @@ -1,118 +0,0 @@ -# -*- coding: utf-8 -*- -# vi:si:et:sw=4:sts=4:ts=4 - -## -## Copyright (C) 2011-2012 Async Open Source -## All rights reserved -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., or visit: http://www.gnu.org/. -## -## Author(s): Stoq Team -## -"""Test pyflakes on stoq, stoqlib and plugins directories - -Useful to early find syntax errors and other common problems. - -""" -import _ast -import sys -import unittest - -from testutils import SourceTest -from compat import skipIf - - -try: - from pyflakes import checker -except ImportError as err: - if sys.version_info >= (3,): - pass # Pyflakes doesn't support Python3 - else: - raise(err) - - -@skipIf(sys.version_info >= (3,), - "Pyflakes unavailable on this version") -class TestPyflakes(SourceTest, unittest.TestCase): - def setUp(self): - pass - - # stolen from pyflakes - def _check(self, codeString, filename, warnings): - try: - tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST) - except (SyntaxError, IndentationError) as value: - msg = value.args[0] - - (lineno, offset, text) = value.lineno, value.offset, value.text - - # If there's an encoding problem with the file, the text is None. - if text is None: - # Avoid using msg, since for the only known case, it contains a - # bogus message that claims the encoding the file declared was - # unknown. - print >> sys.stderr, "%s: problem decoding source" % ( - filename, - ) - else: - line = text.splitlines()[-1] - - if offset is not None: - offset = offset - (len(text) - len(line)) - - print >> sys.stderr, '%s:%d: %s' % (filename, lineno, msg) - print >> sys.stderr, line - - if offset is not None: - print >> sys.stderr, " " * offset, "^" - - return 1 - except UnicodeError as msg: - print >> sys.stderr, 'encoding error at %r: %s' % (filename, msg) - return 1 - else: - # Okay, it's syntactically valid. - # Now parse it into an ast and check it. - w = checker.Checker(tree, filename) - warnings.extend(w.messages) - return len(warnings) - - def check_filename(self, root, filename): - warnings = [] - msgs = [] - result = 0 - try: - fd = open(filename, 'U') - try: - result = self._check(fd.read(), filename, warnings) - finally: - fd.close() - except IOError as msg: - print >> sys.stderr, "%s: %s" % (filename, msg.args[1]) - result = 1 - - warnings.sort(key=lambda w: w.lineno) - for warning in warnings: - msg = str(warning).replace(root, '') - print msg - msgs.append(msg) - if result: - raise AssertionError( - "%d warnings:\n%s\n" % (len(msgs), '\n'.join(msgs), )) - -suite = unittest.TestLoader().loadTestsFromTestCase(TestPyflakes) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/testutils.py b/tests/testutils.py deleted file mode 100644 index 18407138..00000000 --- a/tests/testutils.py +++ /dev/null @@ -1,83 +0,0 @@ -# -*- coding: utf-8 -*- -import fnmatch -import os - -import pysped - - -def list_recursively(directory, pattern): - """Returns files recursively from directory matching pattern - :param directory: directory to list - :param pattern: glob mattern to match - """ - matches = [] - for root, dirnames, filenames in os.walk(directory): - for filename in fnmatch.filter(filenames, pattern): - # skip backup files - if (filename.startswith('.#') or - filename.endswith('~')): - continue - matches.append(os.path.join(root, filename)) - return matches - - -def get_sources(root): - for dirpath in ['pysped', 'tests']: - path = os.path.join(root, dirpath) - for fname in list_recursively(path, '*.py'): - if fname.endswith('__init__.py'): - continue - yield fname - - #yield os.path.join(root, 'setup.py') - - -class ClassInittableMetaType(type): - # pylint fails to understand this is a metaclass - def __init__(self, name, bases, namespace): - type.__init__(self, name, bases, namespace) - self.__class_init__(namespace) - - -class SourceTest(object): - __metaclass__ = ClassInittableMetaType - - @classmethod - def __class_init__(cls, namespace): - root = os.path.dirname(os.path.dirname(pysped.__file__)) - cls.root = root - for filename in get_sources(root): - testname = filename[len(root):] - if not cls.filename_filter(testname): - continue - testname = testname[:-3].replace('/', '_') - name = 'test_%s' % (testname, ) - func = lambda self, r=root, f=filename: self.check_filename(r, f) - func.__name__ = name - setattr(cls, name, func) - - def check_filename(self, root, filename): - pass - - @classmethod - def filename_filter(cls, filename): - if cls.__name__ == 'SourceTest': - return False - else: - return True - - -def indent(elem, level=0): - i = "\n" + level * " " - if len(elem): - if not elem.text or not elem.text.strip(): - elem.text = i + " " - if not elem.tail or not elem.tail.strip(): - elem.tail = i - for elem in elem: - indent(elem, level + 1) - if not elem.tail or not elem.tail.strip(): - elem.tail = i - else: - if level and (not elem.tail or not elem.tail.strip()): - elem.tail = i diff --git a/travis_run_script.sh b/travis_run_script.sh new file mode 100644 index 00000000..99e8b091 --- /dev/null +++ b/travis_run_script.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +if [ "${TEST}" != "0" ]; then + bin/python setup.py test + exit 0 +fi + +if [ "${FLAKE}" != "0" ]; then + bin/python setup.py flake8 + exit 0 +fi + +if [ "${LINT}" != "0" ]; then + bin/python setup.py lint + exit 0 +fi + +set +e \ No newline at end of file