|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | 3 | """Helper routines for running other unit tests. |
4 | | -
|
5 | | -TestCaseObjCrystOptional -- use this as a TestCase base class that |
6 | | - disables unit tests when pyobjcryst is not installed. |
7 | | -
|
8 | | -TestCasePeriodictableOptional -- use this as a TestCase base class to |
9 | | - skip unit tests when periodictable is not installed. |
10 | 4 | """ |
11 | 5 |
|
12 | 6 |
|
|
16 | 10 | from diffpy.srreal.structureconverters import convertObjCrystCrystal |
17 | 11 | from diffpy.srreal.tests import logger |
18 | 12 |
|
19 | | -# class TestCaseObjCrystOptional |
| 13 | +# Resolve availability of optional packages. |
| 14 | + |
| 15 | +# pyobjcryst |
20 | 16 |
|
| 17 | +_msg_nopyobjcryst = "No module named 'pyobjcryst'" |
21 | 18 | try: |
22 | 19 | import pyobjcryst.crystal |
23 | | - from unittest import TestCase as TestCaseObjCrystOptional |
24 | 20 | convertObjCrystCrystal(pyobjcryst.crystal.Crystal()) |
| 21 | + has_pyobjcryst = True |
25 | 22 | except ImportError: |
26 | | - TestCaseObjCrystOptional = object |
| 23 | + has_pyobjcryst = False |
27 | 24 | logger.warning('Cannot import pyobjcryst, pyobjcryst tests skipped.') |
28 | 25 | except TypeError: |
29 | | - TestCaseObjCrystOptional = object |
| 26 | + has_pyobjcryst = False |
30 | 27 | logger.warning('Compiled without ObjCryst, pyobjcryst tests skipped.') |
31 | 28 |
|
32 | | -# class TestCasePeriodictableOptional |
| 29 | +# periodictable |
33 | 30 |
|
| 31 | +_msg_noperiodictable = "No module named 'periodictable'" |
34 | 32 | try: |
35 | 33 | import periodictable |
36 | | - from unittest import TestCase as TestCasePeriodictableOptional |
| 34 | + has_periodictable = True |
37 | 35 | # silence the pyflakes syntax checker |
38 | 36 | del periodictable |
39 | 37 | except ImportError: |
40 | | - TestCasePeriodictableOptional = object |
| 38 | + has_periodictable = False |
41 | 39 | logger.warning('Cannot import periodictable, periodictable tests skipped.') |
42 | 40 |
|
43 | 41 | # helper functions |
|
0 commit comments