diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..9f91ecb --- /dev/null +++ b/.drone.yml @@ -0,0 +1,49 @@ +clone: + hg: + image: plugins/hg + +pipeline: + tox: + image: ${IMAGE} + environment: + - CFLAGS=-O0 + - DB_CACHE=/cache + - TOX_TESTENV_PASSENV=CFLAGS DB_CACHE + - POSTGRESQL_URI=postgresql://postgres@postgresql:5432/ + commands: + - pip install tox + - tox -e "${TOXENV}-${DATABASE}" + +services: + postgresql: + image: postgres + when: + matrix: + DATABASE: postgresql + +matrix: + include: + - IMAGE: python:2.7 + TOXENV: py27 + DATABASE: sqlite + - IMAGE: python:2.7 + TOXENV: py27 + DATABASE: postgresql + - IMAGE: python:3.4 + TOXENV: py34 + DATABASE: sqlite + - IMAGE: python:3.4 + TOXENV: py34 + DATABASE: postgresql + - IMAGE: python:3.5 + TOXENV: py35 + DATABASE: sqlite + - IMAGE: python:3.5 + TOXENV: py35 + DATABASE: postgresql + - IMAGE: python:3.6 + TOXENV: py36 + DATABASE: sqlite + - IMAGE: python:3.6 + TOXENV: py36 + DATABASE: postgresql diff --git a/__init__.py b/__init__.py index 4a7db3d..68e0dff 100644 --- a/__init__.py +++ b/__init__.py @@ -1,10 +1,10 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. from trytond.pool import Pool -from shipment import * +from . import shipment def register(): Pool.register( - ShipmentOut, + shipment.ShipmentOut, module='stock_prevent_exceding_quantities', type_='model') diff --git a/setup.py b/setup.py index 1c3d833..2c8ff41 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,11 @@ from setuptools import setup import re import os -import ConfigParser +import io +try: + from configparser import ConfigParser +except ImportError: + from ConfigParser import ConfigParser MODULE = 'stock_prevent_exceding_quantities' PREFIX = 'nantic' @@ -12,7 +16,9 @@ MODULE2PREFIX = {} def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() + return io.open( + os.path.join(os.path.dirname(__file__), fname), + 'r', encoding='utf-8').read() def get_require_version(name): @@ -24,7 +30,7 @@ def get_require_version(name): major_version, minor_version + 1) return require -config = ConfigParser.ConfigParser() +config = ConfigParser() config.readfp(open('tryton.cfg')) info = dict(config.items('tryton')) for key in ('depends', 'extras_depend', 'xml'): @@ -38,14 +44,16 @@ minor_version = int(minor_version) requires = [] for dep in info.get('depends', []): - if not re.match(r'(ir|res|webdav)(\W|$)', dep): + if not re.match(r'(ir|res)(\W|$)', dep): prefix = MODULE2PREFIX.get(dep, 'trytond') - requires.append('%s_%s >= %s.%s, < %s.%s' % - (prefix, dep, major_version, minor_version, - major_version, minor_version + 1)) + requires.append(get_require_version('%s_%s' % (prefix, dep))) requires.append(get_require_version('trytond')) tests_require = [get_require_version('proteus')] +dependency_links = [] +if minor_version % 2: + # Add development index for testing with proteus + dependency_links.append('https://trydevpi.tryton.org/') setup(name='%s_%s' % (PREFIX, MODULE), version=version, @@ -82,12 +90,17 @@ setup(name='%s_%s' % (PREFIX, MODULE), 'Natural Language :: Russian', 'Natural Language :: Spanish', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Office/Business', ], license='GPL-3', install_requires=requires, + dependency_links=dependency_links, zip_safe=False, entry_points=""" [trytond.modules] @@ -96,4 +109,8 @@ setup(name='%s_%s' % (PREFIX, MODULE), test_suite='tests', test_loader='trytond.test_loader:Loader', tests_require=tests_require, + use_2to3=True, + convert_2to3_doctests=[ + 'tests/scenario_stock_prevent_exceding_quantities.rst', + ], ) diff --git a/shipment.py b/shipment.py index ef6ba18..d7a8c07 100644 --- a/shipment.py +++ b/shipment.py @@ -1,12 +1,12 @@ -#This file is part of Tryton. The COPYRIGHT file at the top level of -#this repository contains the full copyright notices and license terms. +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. from trytond.pool import Pool, PoolMeta __all__ = ['ShipmentOut'] -__metaclass__ = PoolMeta class ShipmentOut: + __metaclass__ = PoolMeta __name__ = 'stock.shipment.out' @classmethod diff --git a/tests/__init__.py b/tests/__init__.py index ecd9426..fc3a088 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1,8 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. -from .test_stock_prevent_exceding_quantities import suite +try: + from trytond.modules.stock_prevent_exceding_quantities.tests.test_stock_prevent_exceding_quantities import suite +except ImportError: + from .test_stock_prevent_exceding_quantities import suite + +__all__ = ['suite'] diff --git a/tests/scenario_stock_prevent_exceding_quantities.rst b/tests/scenario_stock_prevent_exceding_quantities.rst index f1f448b..20c84f0 100644 --- a/tests/scenario_stock_prevent_exceding_quantities.rst +++ b/tests/scenario_stock_prevent_exceding_quantities.rst @@ -9,23 +9,14 @@ Imports:: >>> from decimal import Decimal >>> from operator import attrgetter >>> from proteus import config, Model, Wizard + >>> from trytond.tests.tools import activate_modules >>> from trytond.modules.company.tests.tools import create_company, \ ... get_company >>> today = datetime.date.today() -Create database:: - - >>> config = config.set_trytond() - >>> config.pool.test = True - Install stock_prevent_exceding_quantities:: - >>> Module = Model.get('ir.module') - >>> module, = Module.find([ - ... ('name', '=', 'stock_prevent_exceding_quantities') - ... ]) - >>> Module.install([module.id], config.context) - >>> Wizard('ir.module.install_upgrade').execute('upgrade') + >>> config = activate_modules('stock_prevent_exceding_quantities') Create company:: @@ -94,10 +85,10 @@ Try to send exceding quantities with one move:: >>> for move in shipment.inventory_moves: ... move.quantity = 6.0 >>> shipment.save() - >>> ShipmentOut.assign_try([shipment.id], config.context) + >>> ShipmentOut.assign_try([shipment.id], config.context) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ('UserError', (u'Move 6.0u product makes inventory quantities of product "product" exceed outgoing quantities by 1.0 Unit.', '')) + UserError: ... >>> for move in shipment.inventory_moves: ... move.quantity = 5.0 >>> shipment.save() @@ -124,7 +115,7 @@ Try to send exceding quantities with more than one move:: >>> move.to_location = outgoing_loc >>> move.quantity = 1.0 >>> shipment.save() - >>> ShipmentOut.assign_try([shipment.id], config.context) + >>> ShipmentOut.assign_try([shipment.id], config.context) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... - UserError: ('UserError', (u'Move 5.0u product makes inventory quantities of product "product" exceed outgoing quantities by 1.0 Unit.', '')) + UserError: ... diff --git a/tests/test_stock_prevent_exceding_quantities.py b/tests/test_stock_prevent_exceding_quantities.py index e7cff58..0afcf8e 100644 --- a/tests/test_stock_prevent_exceding_quantities.py +++ b/tests/test_stock_prevent_exceding_quantities.py @@ -5,7 +5,7 @@ import unittest import doctest import trytond.tests.test_tryton from trytond.tests.test_tryton import ModuleTestCase -from trytond.tests.test_tryton import doctest_setup, doctest_teardown +from trytond.tests.test_tryton import doctest_teardown from trytond.tests.test_tryton import doctest_checker @@ -19,7 +19,7 @@ def suite(): suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase)) suite.addTests(doctest.DocFileSuite( 'scenario_stock_prevent_exceding_quantities.rst', - setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8', + tearDown=doctest_teardown, encoding='utf-8', checker=doctest_checker, optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ad44320 --- /dev/null +++ b/tox.ini @@ -0,0 +1,18 @@ +[tox] +envlist = {py27,py34,py35,py36}-{sqlite,postgresql,mysql},pypy-{sqlite,postgresql} + +[testenv] +commands = {envpython} setup.py test +deps = + {py27,py34,py35,py36}-postgresql: psycopg2 >= 2.5 + pypy-postgresql: psycopg2cffi >= 2.5 + mysql: MySQL-python + sqlite: sqlitebck +setenv = + sqlite: TRYTOND_DATABASE_URI={env:SQLITE_URI:sqlite://} + postgresql: TRYTOND_DATABASE_URI={env:POSTGRESQL_URI:postgresql://} + mysql: TRYTOND_DATABASE_URI={env:MYSQL_URI:mysql://} + sqlite: DB_NAME={env:SQLITE_NAME::memory:} + postgresql: DB_NAME={env:POSTGRESQL_NAME:test} + mysql: DB_NAME={env:MYSQL_NAME:test} +install_command = pip install --pre --find-links https://trydevpi.tryton.org/ --process-dependency-links {opts} {packages} diff --git a/tryton.cfg b/tryton.cfg index 6a2d089..bb5ec26 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=4.1.0 +version=4.7.0 depends: stock xml: