Make tests compatible with Python 3.7+

pull/3/head
Alinson S. Xavier 5 years ago
parent 57d185dfc2
commit e7426e445a

@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python-version: [3.6, 3.7, 3.8] python-version: [3.6, 3.7, 3.8, 3.9]
steps: steps:
- name: Check out source code - name: Check out source code
@ -24,4 +24,4 @@ jobs:
- name: Test with pytest - name: Test with pytest
run: | run: |
pytest pytest

@ -1,6 +1,6 @@
PYTHON := python3 PYTHON := python3
PYTEST := pytest PYTEST := pytest
PIP := pip3 PIP := $(PYTHON) -m pip
PYTEST_ARGS := -W ignore::DeprecationWarning -vv -x --log-level=DEBUG PYTEST_ARGS := -W ignore::DeprecationWarning -vv -x --log-level=DEBUG
VERSION := 0.2 VERSION := 0.2
@ -24,8 +24,11 @@ docs:
docs-dev: docs-dev:
mkdocs build -d ../docs/dev/ mkdocs build -d ../docs/dev/
install: install-deps:
$(PIP) install -i https://pypi.gurobi.com gurobipy
$(PIP) install -r requirements.txt $(PIP) install -r requirements.txt
install:
$(PYTHON) setup.py install $(PYTHON) setup.py install
uninstall: uninstall:

@ -2,23 +2,29 @@
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved. # Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details. # Released under the modified BSD license. See COPYING.md for more details.
from inspect import isclass
from miplearn import BasePyomoSolver, GurobiSolver, GurobiPyomoSolver from miplearn import BasePyomoSolver, GurobiSolver, GurobiPyomoSolver
from miplearn.problems.knapsack import KnapsackInstance, GurobiKnapsackInstance from miplearn.problems.knapsack import KnapsackInstance, GurobiKnapsackInstance
def _get_instance(solver): def _get_instance(solver):
if issubclass(solver, BasePyomoSolver) or isinstance(solver, BasePyomoSolver): def _is_subclass_or_instance(solver, parentClass):
return isinstance(solver, parentClass) or (isclass(solver) and issubclass(solver, parentClass))
if _is_subclass_or_instance(solver, BasePyomoSolver):
return KnapsackInstance( return KnapsackInstance(
weights=[23., 26., 20., 18.], weights=[23., 26., 20., 18.],
prices=[505., 352., 458., 220.], prices=[505., 352., 458., 220.],
capacity=67., capacity=67.,
) )
if issubclass(solver, GurobiSolver) or isinstance(solver, GurobiSolver):
if _is_subclass_or_instance(solver, GurobiSolver):
return GurobiKnapsackInstance( return GurobiKnapsackInstance(
weights=[23., 26., 20., 18.], weights=[23., 26., 20., 18.],
prices=[505., 352., 458., 220.], prices=[505., 352., 458., 220.],
capacity=67., capacity=67.,
) )
assert False assert False

Loading…
Cancel
Save