Skip to content

Commit be15d50

Browse files
committed
pcmt on tests
1 parent 7780bc3 commit be15d50

11 files changed

+42
-42
lines changed

tests/test_clocks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
import unittest
1818

19-
from pyobjcryst.refinableobj import RefinableObjClock
2019
from utils import makeC60
2120

21+
from pyobjcryst.refinableobj import RefinableObjClock
22+
2223

2324
class TestClocks(unittest.TestCase):
2425

tests/test_crystal.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616

1717
import unittest
1818

19-
from pyobjcryst.atom import Atom
2019
from utils import (
2120
getScatterer,
2221
makeCrystal,
2322
makeScatterer,
2423
makeScattererAnisotropic,
2524
)
2625

26+
from pyobjcryst.atom import Atom
27+
2728

2829
class TestCrystal(unittest.TestCase):
2930

@@ -163,10 +164,10 @@ def __init__(self, level1):
163164
def test_display_list(self):
164165
"""Test the creation of a atoms list for display using 3dmol."""
165166
c = makeCrystal(*makeScatterer())
166-
s = c._display_list()
167-
s = c._display_list(full_molecule=True)
168-
s = c._display_list(enantiomer=True)
169-
s = c._display_list(only_independent_atoms=True)
167+
c._display_list()
168+
c._display_list(full_molecule=True)
169+
c._display_list(enantiomer=True)
170+
c._display_list(only_independent_atoms=True)
170171

171172

172173
if __name__ == "__main__":

tests/test_globaloptim.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111

1212
import unittest
1313

14+
from utils import loadcifdata
15+
1416
from pyobjcryst import refinableobj
1517
from pyobjcryst.diffractiondatasinglecrystal import (
1618
DiffractionDataSingleCrystal,
1719
)
18-
from pyobjcryst.globaloptim import (
19-
AnnealingSchedule,
20-
GlobalOptimType,
21-
MonteCarlo,
22-
)
23-
from utils import loadcifdata
20+
from pyobjcryst.globaloptim import AnnealingSchedule, MonteCarlo
2421

2522

2623
class TestGlobalOptim(unittest.TestCase):
@@ -54,13 +51,13 @@ def test_mc_llk(self):
5451
mc = MonteCarlo()
5552
mc.AddRefinableObj(self.c)
5653
mc.AddRefinableObj(self.d)
57-
junk = mc.GetLogLikelihood()
54+
mc.GetLogLikelihood()
5855

5956
def test_mc_fix_use_pars(self):
6057
mc = MonteCarlo()
6158
mc.AddRefinableObj(self.c)
6259
mc.AddRefinableObj(self.d)
63-
junk = mc.GetLogLikelihood()
60+
mc.GetLogLikelihood()
6461
mc.FixAllPar()
6562
mc.SetParIsUsed("Scale factor", False)
6663
mc.SetParIsUsed("Scale factor", True)
@@ -99,7 +96,8 @@ def test_mc_pt(self):
9996
mc.RandomizeStartingConfig()
10097
mc.RunParallelTempering(nb_step=1000)
10198

102-
# TODO: this is experimental and leads to segfault if testcrystal:testDummyAtom() has been run before (?!)
99+
# TODO: this is experimental and leads to segfault if
100+
# testcrystal:testDummyAtom() has been run before (?!)
103101
# def test_mc_lsq(self):
104102
# mc = MonteCarlo()
105103
# mc.AddRefinableObj(self.c)

tests/test_indexing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from numpy import pi
1515

1616
from pyobjcryst.indexing import (
17-
CellExplorer,
1817
CrystalCentering,
1918
CrystalSystem,
2019
EstimateCellVolume,

tests/test_lsq.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
import unittest
1313

14+
from utils import loadcifdata
15+
1416
from pyobjcryst import refinableobj
1517
from pyobjcryst.diffractiondatasinglecrystal import (
1618
DiffractionDataSingleCrystal,
1719
)
1820
from pyobjcryst.lsq import LSQ
19-
from utils import loadcifdata
2021

2122

2223
class TestGlobalOptim(unittest.TestCase):
@@ -40,7 +41,9 @@ def test_lsq_get_obs_calc(self):
4041
"""Check Creating a basic LSQ object & get obs&calc arrays."""
4142
lsq = LSQ()
4243
lsq.SetRefinedObj(self.d, 0, True, True)
43-
junk = lsq.GetLSQObs(), lsq.GetLSQCalc(), lsq.ChiSquare()
44+
lsq.GetLSQObs()
45+
lsq.GetLSQCalc()
46+
lsq.ChiSquare()
4447

4548
def test_lsq_get_refined_obj(self):
4649
"""Check Creating a basic LSQ object & get obs&calc arrays."""

tests/test_molecule.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
##############################################################################
1515
"""Tests for molecule module."""
1616

17-
import io
1817
import unittest
1918
from importlib.resources import files
2019

2120
from numpy import pi
21+
from utils import makeC60, makeMnO6
2222

2323
from pyobjcryst import ObjCrystException
2424
from pyobjcryst.crystal import Crystal
@@ -32,7 +32,6 @@
3232
StretchModeTorsion,
3333
)
3434
from pyobjcryst.refinableobj import RefinablePar, RefParType
35-
from utils import makeC60, makeMnO6
3635

3736
numplaces = 6
3837

@@ -117,7 +116,7 @@ def testAtoms(self):
117116
# First, try the same atom again. This will throw an objcryst error.
118117
self.assertRaises(ObjCrystException, self.m.RemoveAtom, a)
119118

120-
## Try to remove an atom from another molecule
119+
# Try to remove an atom from another molecule
121120
c = makeC60()
122121
m = c.GetScatterer("c60")
123122
self.assertRaises(ObjCrystException, self.m.RemoveAtom, m.GetAtom(1))

tests/test_powderpattern.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
import unittest
1818

1919
import numpy as np
20+
from utils import loadcifdata
2021

2122
from pyobjcryst import ObjCrystException
22-
from pyobjcryst.crystal import *
23-
from pyobjcryst.indexing import *
23+
from pyobjcryst.indexing import CrystalCentering, CrystalSystem, quick_index
2424
from pyobjcryst.powderpattern import PowderPattern, SpaceGroupExplorer
2525
from pyobjcryst.radiation import RadiationType, WavelengthType
2626
from pyobjcryst.reflectionprofile import ReflectionProfileType
27-
from utils import datafile, loadcifdata
2827

2928
# ----------------------------------------------------------------------------
3029

@@ -232,7 +231,7 @@ def test_spacegroup_explorer(self):
232231
spgex = SpaceGroupExplorer(pd)
233232
spgex.Run("P 1 21/c 1")
234233
spgex.RunAll(verbose=False)
235-
spg = spgex.GetScores()[0]
234+
spg = spgex.GetScores()[0] # noqa F841
236235
# This fails about XX% of the time (fit not converging well enough ?)
237236
# self.assertEqual(spg.hermann_mauguin, 'P 1 21/c 1')
238237
# if True: #spg.hermann_mauguin != 'P 1 21/c 1':

tests/test_radiation.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@
1111

1212
import unittest
1313

14-
from pyobjcryst.diffractiondatasinglecrystal import (
15-
DiffractionDataSingleCrystal,
16-
)
17-
from pyobjcryst.powderpattern import PowderPattern
1814
from pyobjcryst.radiation import Radiation, RadiationType, WavelengthType
1915

2016

2117
class TestRadiation(unittest.TestCase):
2218

2319
def testRadiation(self):
2420
"""Test Radiation creation."""
25-
r = Radiation()
21+
Radiation()
2622
return
2723

2824
def testWavelength(self):

tests/test_refinableobj.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import unittest
1818

1919
import numpy
20+
from utils import makeCrystal, makeScatterer
2021

2122
from pyobjcryst import ObjCrystException
2223
from pyobjcryst.refinableobj import (
@@ -26,7 +27,6 @@
2627
RefParType,
2728
Restraint,
2829
)
29-
from utils import makeCrystal, makeScatterer
3030

3131

3232
class TestRefinableObjClock(unittest.TestCase):
@@ -421,7 +421,7 @@ def testOptimStep(self):
421421

422422
def test_xml(self):
423423
"""Test xml() function."""
424-
x = self.r.xml()
424+
self.r.xml()
425425

426426

427427
if __name__ == "__main__":

tests/test_single_crystal_data.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,46 @@
33
"""Tests for diffractiondatasinglecrystal module."""
44

55
import unittest
6+
67
import numpy as np
78

89
from pyobjcryst.crystal import Crystal
9-
from pyobjcryst.diffractiondatasinglecrystal import DiffractionDataSingleCrystal
10+
from pyobjcryst.diffractiondatasinglecrystal import (
11+
DiffractionDataSingleCrystal,
12+
)
1013

1114

1215
class test_single_crystal_data(unittest.TestCase):
1316

1417
def test_create(self):
15-
"""Test creating a DiffractionDataSingleCrystal object"""
18+
"""Test creating a DiffractionDataSingleCrystal object."""
1619
c = Crystal(3.52, 3.52, 3.52, "225")
17-
d = DiffractionDataSingleCrystal(c)
20+
DiffractionDataSingleCrystal(c)
1821

1922
def test_create_set_hkliobs(self):
20-
"""test SetHklIobs, SetIobs and SetSigma"""
23+
"""Test SetHklIobs, SetIobs and SetSigma."""
2124
c = Crystal(3.1, 3.2, 3.3, "Pmmm")
2225
d = DiffractionDataSingleCrystal(c)
2326
n0 = 5
24-
nb = n0 ** 3
27+
nb = n0**3
2528
r = np.arange(1, nb + 1, dtype=np.float64)
2629
h = r % n0
27-
l = r // n0 ** 2
28-
k = (r - l * n0 ** 2) // n0
30+
l = r // n0**2 # noqa: E741
31+
k = (r - l * n0**2) // n0
2932
iobs = np.random.uniform(0, 100, nb)
3033
sigma = np.sqrt(iobs)
3134

3235
d.SetHklIobs(h, k, l, iobs, sigma)
3336

3437
# SetHklIobs sorts reflecions by sin(theta)/lambda, so do the same for comparison
35-
s = np.sqrt(h ** 2 / 3.1 ** 2 + k ** 2 / 3.2 ** 2 + l ** 2 / 3.3 ** 2) / 2
38+
s = np.sqrt(h**2 / 3.1**2 + k**2 / 3.2**2 + l**2 / 3.3**2) / 2
3639
idx = np.argsort(s)
3740

3841
iobs = np.take(iobs, idx)
3942
sigma = np.take(sigma, idx)
4043
h = np.take(h, idx)
4144
k = np.take(k, idx)
42-
l = np.take(l, idx)
45+
l = np.take(l, idx) # noqa: E741
4346
self.assertTrue(np.all(iobs == d.GetIobs()))
4447
self.assertTrue(np.all(sigma == d.GetSigma()))
4548
self.assertTrue(np.all(h == d.GetH()))
@@ -55,5 +58,6 @@ def test_create_set_hkliobs(self):
5558
d.SetSigma(sigma)
5659
self.assertTrue(np.all(sigma == d.GetSigma()))
5760

61+
5862
if __name__ == "__main__":
5963
unittest.main()

0 commit comments

Comments
 (0)