Skip to content

Commit 685df37

Browse files
committed
merging pre-commit changes. test_builder.py now passing tests
2 parents 2338ba4 + e54ef40 commit 685df37

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

tests/conftest.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import json
2-
from pathlib import Path
31
import importlib.resources
4-
import pytest
2+
import json
53
import logging
6-
74
from functools import lru_cache
5+
from pathlib import Path
6+
7+
import pytest
88
import diffpy.srfit.equation.literals as literals
99
from diffpy.srfit.sas.sasimport import sasimport
1010

1111

1212
logger = logging.getLogger(__name__)
1313

14+
1415
@lru_cache()
1516
def has_sas():
1617
try:
@@ -20,36 +21,45 @@ def has_sas():
2021
except ImportError:
2122
return False
2223

24+
2325
# diffpy.structure
2426
@lru_cache()
2527
def has_diffpy_structure():
2628
_msg_nostructure = "No module named 'diffpy.structure'"
2729
try:
2830
import diffpy.structure as m
31+
2932
del m
3033
return True
3134
except ImportError:
3235
return False
33-
logger.warning("Cannot import diffpy.structure, Structure tests skipped.")
36+
logger.warning(
37+
"Cannot import diffpy.structure, Structure tests skipped."
38+
)
39+
3440

3541
@lru_cache()
3642
def has_pyobjcryst():
3743
_msg_nopyobjcryst = "No module named 'pyobjcryst'"
3844
try:
3945
import pyobjcryst as m
46+
4047
del m
4148
return True
4249
except ImportError:
4350
return False
4451
logger.warning("Cannot import pyobjcryst, pyobjcryst tests skipped.")
4552

53+
4654
# diffpy.srreal
4755

56+
4857
@lru_cache()
4958
def has_diffpy_srreal():
5059
_msg_nosrreal = "No module named 'diffpy.srreal'"
5160
try:
5261
import diffpy.srreal.pdfcalculator as m
62+
5363
del m
5464
return True
5565
except ImportError:
@@ -61,14 +71,17 @@ def has_diffpy_srreal():
6171
def sas_available():
6272
return has_sas()
6373

74+
6475
@pytest.fixture(scope="session")
6576
def diffpy_structure_available():
6677
return has_diffpy_structure()
6778

79+
6880
@pytest.fixture(scope="session")
6981
def diffpy_srreal_available():
7082
return has_diffpy_srreal()
7183

84+
7285
@pytest.fixture(scope="session")
7386
def pyobjcryst_available():
7487
return has_pyobjcryst()
@@ -92,8 +105,12 @@ def user_filesystem(tmp_path):
92105
@pytest.fixture
93106
def datafile():
94107
"""Fixture to load a test data file from the testdata package directory."""
108+
95109
def _datafile(filename):
96-
return importlib.resources.files("diffpy.srfit.tests.testdata").joinpath(filename)
110+
return importlib.resources.files(
111+
"diffpy.srfit.tests.testdata"
112+
).joinpath(filename)
113+
97114
return _datafile
98115

99116
@pytest.fixture(scope="session")

tests/test_sas.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
##############################################################################
1515
"""Tests for sas package."""
1616

17-
import pytest
1817
import numpy
18+
import pytest
1919

2020
from diffpy.srfit.sas import SASGenerator, SASParser, SASProfile
2121
from diffpy.srfit.sas.sasimport import sasimport
@@ -24,6 +24,7 @@
2424
# FIXME: adjust sensitivity of the pytest.approx statements when ready to test
2525
# with sasview installed.
2626

27+
2728
def testParser(sas_available, datafile):
2829
if not sas_available:
2930
pytest.skip("sas package not available")
@@ -135,6 +136,7 @@ def test_generator(sas_available):
135136
assert 0 == pytest.approx(res)
136137
return
137138

139+
138140
def testGenerator2(sas_available, datafile):
139141
if not sas_available:
140142
pytest.skip("sas package not available")

tests/test_sgconstraints.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import numpy
2020

21-
2221
# ----------------------------------------------------------------------------
2322

2423

tests/utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@
2020

2121
import diffpy.srfit.equation.literals as literals
2222
from diffpy.srfit.sas.sasimport import sasimport
23-
2423
from tests import logger
2524

26-
2725
# Helper functions for testing -----------------------------------------------
2826

2927

3028

3129

32-
3330
def capturestdout(f, *args, **kwargs):
3431
"""Capture the standard output from a call of function f."""
3532
savestdout = sys.stdout

0 commit comments

Comments
 (0)