From e7426e445a9bf8bd1110bb75602d9c10e6a5d906 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Thu, 3 Dec 2020 12:00:32 -0600 Subject: [PATCH] Make tests compatible with Python 3.7+ --- .github/workflows/test.yml | 4 ++-- Makefile | 7 +++++-- miplearn/solvers/tests/__init__.py | 10 ++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80c757a..99c99d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8] + python-version: [3.6, 3.7, 3.8, 3.9] steps: - name: Check out source code @@ -24,4 +24,4 @@ jobs: - name: Test with pytest run: | - pytest \ No newline at end of file + pytest diff --git a/Makefile b/Makefile index b31d525..376f6ff 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PYTHON := python3 PYTEST := pytest -PIP := pip3 +PIP := $(PYTHON) -m pip PYTEST_ARGS := -W ignore::DeprecationWarning -vv -x --log-level=DEBUG VERSION := 0.2 @@ -24,8 +24,11 @@ docs: docs-dev: mkdocs build -d ../docs/dev/ -install: +install-deps: + $(PIP) install -i https://pypi.gurobi.com gurobipy $(PIP) install -r requirements.txt + +install: $(PYTHON) setup.py install uninstall: diff --git a/miplearn/solvers/tests/__init__.py b/miplearn/solvers/tests/__init__.py index 74b35bc..b7e3e61 100644 --- a/miplearn/solvers/tests/__init__.py +++ b/miplearn/solvers/tests/__init__.py @@ -2,23 +2,29 @@ # Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved. # Released under the modified BSD license. See COPYING.md for more details. +from inspect import isclass from miplearn import BasePyomoSolver, GurobiSolver, GurobiPyomoSolver from miplearn.problems.knapsack import KnapsackInstance, GurobiKnapsackInstance 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( weights=[23., 26., 20., 18.], prices=[505., 352., 458., 220.], capacity=67., ) - if issubclass(solver, GurobiSolver) or isinstance(solver, GurobiSolver): + + if _is_subclass_or_instance(solver, GurobiSolver): return GurobiKnapsackInstance( weights=[23., 26., 20., 18.], prices=[505., 352., 458., 220.], capacity=67., ) + assert False