Skip to content

Commit 5c1ae97

Browse files
committed
Add tests for relocated_module()
1 parent db873e6 commit 5c1ae97

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

pyomo/common/tests/relo_mod.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ___________________________________________________________________________
2+
#
3+
# Pyomo: Python Optimization Modeling Objects
4+
# Copyright (c) 2008-2022
5+
# National Technology and Engineering Solutions of Sandia, LLC
6+
# Under the terms of Contract DE-NA0003525 with National Technology and
7+
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
8+
# rights in this software.
9+
# This software is distributed under the 3-clause BSD License.
10+
# ___________________________________________________________________________
11+
12+
from pyomo.common.deprecation import relocated_module
13+
14+
relocated_module('pyomo.common.tests.relo_mod_new', version='1.2')

pyomo/common/tests/relo_mod_new.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ___________________________________________________________________________
2+
#
3+
# Pyomo: Python Optimization Modeling Objects
4+
# Copyright (c) 2008-2022
5+
# National Technology and Engineering Solutions of Sandia, LLC
6+
# Under the terms of Contract DE-NA0003525 with National Technology and
7+
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
8+
# rights in this software.
9+
# This software is distributed under the 3-clause BSD License.
10+
# ___________________________________________________________________________
11+
12+
RELO_ATTR = 42
13+
14+
class ReloClass(object): pass

pyomo/common/tests/test_deprecated.py

+19
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,25 @@ def test_relocated_message(self):
425425
"DEPRECATED: the 'oldName' class has been moved to "
426426
"'pyomo.common.tests.test_deprecated.TestRelocated'")
427427

428+
def test_relocated_module(self):
429+
with LoggingIntercept() as LOG:
430+
# Can import attributes defined only in the new module
431+
from pyomo.common.tests.relo_mod import ReloClass
432+
self.assertRegex(
433+
LOG.getvalue().replace('\n', ' '),
434+
r"DEPRECATED: The 'pyomo\.common\.tests\.relo_mod' module has "
435+
r"been moved to 'pyomo\.common\.tests\.relo_mod_new'. Please "
436+
r"update your import. \(deprecated in 1\.2\) \(called from "
437+
r".*/pyomo/common/tests/test_deprecated\.py")
438+
with LoggingIntercept() as LOG:
439+
# Second import: no warning
440+
import pyomo.common.tests.relo_mod as relo
441+
self.assertEqual(LOG.getvalue(), '')
442+
import pyomo.common.tests.relo_mod_new as relo_new
443+
self.assertIs(relo, relo_new)
444+
self.assertEqual(relo.RELO_ATTR, 42)
445+
self.assertIs(ReloClass, relo_new.ReloClass)
446+
428447

429448
class TestRenamedClass(unittest.TestCase):
430449
def test_renamed(self):

0 commit comments

Comments
 (0)