diff --git a/doc/source/examples/distanceprinter.py b/doc/source/examples/distanceprinter.py index a4b9598..870c721 100755 --- a/doc/source/examples/distanceprinter.py +++ b/doc/source/examples/distanceprinter.py @@ -1,22 +1,25 @@ #!/usr/bin/env python -"""Demonstration of using PairQuantity class for a printout of pair distances -in periodic and non-periodic structures.""" +"""Demonstration of using PairQuantity class for a printout of pair +distances in periodic and non-periodic structures.""" from diffpy.srreal.pairquantity import PairQuantity from diffpy.structure import Structure class DistancePrinter(PairQuantity): - """This PairQuantity class simply prints the visited pair distances and the - indices of the contributing atoms.""" + """This PairQuantity class simply prints the visited pair distances + and the indices of the contributing atoms.""" def _resetValue(self): self.count = 0 def _addPairContribution(self, bnds, sumscale): self.count += bnds.multiplicity() * sumscale / 2.0 - print("%i %g %i %i" % (self.count, bnds.distance(), bnds.site0(), bnds.site1())) + print( + "%i %g %i %i" + % (self.count, bnds.distance(), bnds.site0(), bnds.site1()) + ) return diff --git a/doc/source/examples/lennardjones/ljcalculator.py b/doc/source/examples/lennardjones/ljcalculator.py index 5dc5d85..4e1e151 100755 --- a/doc/source/examples/lennardjones/ljcalculator.py +++ b/doc/source/examples/lennardjones/ljcalculator.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -"""Demonstration of using PairQuantity class for calculation of Lennard Jones -potential. +"""Demonstration of using PairQuantity class for calculation of Lennard +Jones potential. Vij = 4 * ( rij ** -12 - rij ** -6 ) """ diff --git a/doc/source/examples/parallelPDF.py b/doc/source/examples/parallelPDF.py index 3051639..199ebaa 100755 --- a/doc/source/examples/parallelPDF.py +++ b/doc/source/examples/parallelPDF.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -"""Demonstration of parallel PDF calculation using the multiprocessing package. +"""Demonstration of parallel PDF calculation using the multiprocessing +package. A PDF of menthol structure is first calculated on a single core and then on all computer CPUs. The script then compares both results and prints @@ -25,7 +26,11 @@ # configure options parsing parser = optparse.OptionParser("%prog [options]\n" + __doc__) -parser.add_option("--pyobjcryst", action="store_true", help="Use pyobjcryst to load the CIF file.") +parser.add_option( + "--pyobjcryst", + action="store_true", + help="Use pyobjcryst to load the CIF file.", +) parser.allow_interspersed_args = True opts, args = parser.parse_args(sys.argv[1:]) diff --git a/news/pc-blackv2.rst b/news/pc-blackv2.rst new file mode 100644 index 0000000..64feaf3 --- /dev/null +++ b/news/pc-blackv2.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Configure ``black`` to have a linelength requirement of 79 characters. + +**Security:** + +* diff --git a/pyproject.toml b/pyproject.toml index 26eafc6..38694f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ ignore-words = ".codespell/ignore_words.txt" skip = "*.cif,*.dat" [tool.black] -line-length = 115 +line-length = 79 include = '\.pyi?$' exclude = ''' /( @@ -78,3 +78,8 @@ exclude = ''' | tests/data )/ ''' + +[tool.docformatter] +recursive = true +wrap-summaries = 72 +wrap-descriptions = 72 diff --git a/setup.py b/setup.py index fb542c2..d781a2a 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,8 @@ def get_boost_config(): conda_prefix = os.environ.get("CONDA_PREFIX") if not conda_prefix: raise EnvironmentError( - "Neither BOOST_PATH nor CONDA_PREFIX are set. " "Please install Boost or set BOOST_PATH." + "Neither BOOST_PATH nor CONDA_PREFIX are set. " + "Please install Boost or set BOOST_PATH." ) if os.name == "nt": inc = Path(conda_prefix) / "Library" / "include" @@ -52,7 +53,8 @@ def get_objcryst_libraries(): conda_prefix = os.environ.get("CONDA_PREFIX") if not conda_prefix: raise EnvironmentError( - "CONDA_PREFIX is not set. Please install ObjCryst using conda and activate the environment." + "CONDA_PREFIX is not set. " + "Please install ObjCryst using conda and activate the environment." ) if os.name == "nt": libdir = Path(conda_prefix) / "Library" / "lib" @@ -64,7 +66,8 @@ def get_objcryst_libraries(): stem = Path(fn).stem if "objcryst" not in stem.lower(): continue - # strip a leading "lib" so that setuptools does -lObjCryst, not -llibObjCryst + # strip a leading "lib" + # so that setuptools does -lObjCryst, not -llibObjCryst if os.name != "nt" and stem.startswith("lib"): stem = stem[3:] libs.append(stem) @@ -99,7 +102,11 @@ def get_objcryst_libraries(): def create_extensions(): "Initialize Extension objects for the setup function." - ext = Extension("diffpy.srreal.srreal_ext", glob.glob("src/extensions/*.cpp"), **ext_kws) + ext = Extension( + "diffpy.srreal.srreal_ext", + glob.glob("src/extensions/*.cpp"), + **ext_kws, + ) return [ext] diff --git a/src/diffpy/srreal/_docstrings.py b/src/diffpy/srreal/_docstrings.py index ab2cb88..a743a98 100644 --- a/src/diffpy/srreal/_docstrings.py +++ b/src/diffpy/srreal/_docstrings.py @@ -18,7 +18,8 @@ def get_registry_docstrings(cls): - """Build a dictionary of docstrings per each HasClassRegistry method. + """Build a dictionary of docstrings per each HasClassRegistry + method. Parameters ---------- diff --git a/src/diffpy/srreal/_final_imports.py b/src/diffpy/srreal/_final_imports.py index 273f106..b61e0dc 100644 --- a/src/diffpy/srreal/_final_imports.py +++ b/src/diffpy/srreal/_final_imports.py @@ -25,7 +25,8 @@ def import_now(): - """Import all Python modules that tweak extension-defined classes.""" + """Import all Python modules that tweak extension-defined + classes.""" global _import_now_called if _import_now_called: return diff --git a/src/diffpy/srreal/atomradiitable.py b/src/diffpy/srreal/atomradiitable.py index 9d1f03f..9bcf9bd 100644 --- a/src/diffpy/srreal/atomradiitable.py +++ b/src/diffpy/srreal/atomradiitable.py @@ -63,9 +63,9 @@ def clone(self): return copy.copy(self) def type(self): - """Unique string identifier of the CovalentRadiiTable type. This is - used for class registration and as an argument for the createByType - function. + """Unique string identifier of the CovalentRadiiTable type. This + is used for class registration and as an argument for the + createByType function. Return string. """ diff --git a/src/diffpy/srreal/attributes.py b/src/diffpy/srreal/attributes.py index e0326a9..3e188ca 100644 --- a/src/diffpy/srreal/attributes.py +++ b/src/diffpy/srreal/attributes.py @@ -36,7 +36,8 @@ def _getattr(self, name): def _setattr(self, name, value): - """Assign to C++ double attribute if Python attribute does not exist.""" + """Assign to C++ double attribute if Python attribute does not + exist.""" try: object.__getattribute__(self, name) except AttributeError: diff --git a/src/diffpy/srreal/bondcalculator.py b/src/diffpy/srreal/bondcalculator.py index 281ea7d..98d2fe8 100644 --- a/src/diffpy/srreal/bondcalculator.py +++ b/src/diffpy/srreal/bondcalculator.py @@ -43,8 +43,8 @@ def _init_kwargs(self, **kwargs): - """Create a new instance of BondCalculator. Keyword arguments can be used - to configure calculator properties, for example: + """Create a new instance of BondCalculator. Keyword arguments can be + used to configure calculator properties, for example: bdc = BondCalculator(rmin=1.5, rmax=2.5) diff --git a/src/diffpy/srreal/devutils/tunePeakPrecision.py b/src/diffpy/srreal/devutils/tunePeakPrecision.py index c6f3cc9..d899ea5 100755 --- a/src/diffpy/srreal/devutils/tunePeakPrecision.py +++ b/src/diffpy/srreal/devutils/tunePeakPrecision.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -"""Tune the peak precision parameter so that PDFCalculator gives equivalent -results to diffpy.pdffit2. +"""Tune the peak precision parameter so that PDFCalculator gives +equivalent results to diffpy.pdffit2. Usage: tunePeakPrecision.py [qmax] [peakprecision] [createplot] """ @@ -108,7 +108,9 @@ def comparePDFCalculators(qmax, peakprecision=None): rv = {} rv["qmax"] = qmax rv["peakprecision"] = ( - peakprecision is None and PDFCalculator()._getDoubleAttr("peakprecision") or peakprecision + peakprecision is None + and PDFCalculator()._getDoubleAttr("peakprecision") + or peakprecision ) ttic = time.clock() rg0 = Gpdffit2(qmax) @@ -175,7 +177,10 @@ def main(): processCommandLineArguments() cmpdata = comparePDFCalculators(qmax, peakprecision) print( - ("qmax = %(qmax)g pkprec = %(peakprecision)g " + "grmsd = %(grmsd)g t0 = %(t0).3f t1 = %(t1).3f") + ( + "qmax = %(qmax)g pkprec = %(peakprecision)g " + + "grmsd = %(grmsd)g t0 = %(t0).3f t1 = %(t1).3f" + ) % cmpdata ) if createplot: diff --git a/src/diffpy/srreal/eventticker.py b/src/diffpy/srreal/eventticker.py index 35b7487..58d9556 100644 --- a/src/diffpy/srreal/eventticker.py +++ b/src/diffpy/srreal/eventticker.py @@ -12,7 +12,8 @@ # See LICENSE.txt for license information. # ############################################################################## -"""Class EventTicker -- storage of modification times of dependent objects.""" +"""Class EventTicker -- storage of modification times of dependent +objects.""" # exported items diff --git a/src/diffpy/srreal/overlapcalculator.py b/src/diffpy/srreal/overlapcalculator.py index ab41037..e0fcaa4 100644 --- a/src/diffpy/srreal/overlapcalculator.py +++ b/src/diffpy/srreal/overlapcalculator.py @@ -12,7 +12,8 @@ # See LICENSE_DANSE.txt for license information. # ############################################################################## -"""Class OverlapCalculator -- calculator of atom overlaps in a structure.""" +"""Class OverlapCalculator -- calculator of atom overlaps in a +structure.""" # exported items, these also makes them show in pydoc. @@ -50,8 +51,8 @@ def _init_kwargs(self, **kwargs): - """Create a new instance of OverlapCalculator. Keyword arguments can be - used to configure calculator properties, for example: + """Create a new instance of OverlapCalculator. Keyword arguments can + be used to configure calculator properties, for example: olc = OverlapCalculator(rmax=2.5) diff --git a/src/diffpy/srreal/pairquantity.py b/src/diffpy/srreal/pairquantity.py index a8eaa05..7097e7c 100644 --- a/src/diffpy/srreal/pairquantity.py +++ b/src/diffpy/srreal/pairquantity.py @@ -12,7 +12,8 @@ # See LICENSE_DANSE.txt for license information. # ############################################################################## -"""Class PairQuantity -- base class for Python defined calculators.""" +"""Class PairQuantity -- base class for Python defined +calculators.""" # exported items diff --git a/src/diffpy/srreal/parallel.py b/src/diffpy/srreal/parallel.py index 5ab113e..179f092 100644 --- a/src/diffpy/srreal/parallel.py +++ b/src/diffpy/srreal/parallel.py @@ -43,8 +43,8 @@ def createParallelCalculator(pqobj, ncpu, pmap): """ class ParallelPairQuantity(Attributes): - """Class for running parallel calculations. This is a proxy class to - the wrapper PairQuantity type with the same interface. + """Class for running parallel calculations. This is a proxy + class to the wrapper PairQuantity type with the same interface. Instance data: @@ -70,7 +70,8 @@ def __init__(self, pqobj, ncpu, pmap): return def eval(self, stru=None): - """Perform parallel calculation and return internal value array. + """Perform parallel calculation and return internal value + array. stru -- object that can be converted to StructureAdapter, e.g., example diffpy Structure or pyobjcryst Crystal. @@ -163,7 +164,9 @@ def proxymethod(self, *args, **kwargs): return proxymethod for n, f in inspect.getmembers(pqtype, inspect.isroutine): - ignore = n not in proxy_forced and (n.startswith("_") or hasattr(ParallelPairQuantity, n)) + ignore = n not in proxy_forced and ( + n.startswith("_") or hasattr(ParallelPairQuantity, n) + ) if ignore: continue setattr(ParallelPairQuantity, n, _make_proxymethod(n, f)) @@ -206,7 +209,8 @@ def _fdel(self): def _parallelData(kwd): - """Helper for calculating and fetching raw results from a worker node.""" + """Helper for calculating and fetching raw results from a worker + node.""" pqobj = kwd["pqobj"] pqobj._setupParallelRun(kwd["cpuindex"], kwd["ncpu"]) pqobj.eval() diff --git a/src/diffpy/srreal/pdfbaseline.py b/src/diffpy/srreal/pdfbaseline.py index 22ced38..bb16846 100644 --- a/src/diffpy/srreal/pdfbaseline.py +++ b/src/diffpy/srreal/pdfbaseline.py @@ -48,8 +48,9 @@ def makePDFBaseline(name, fnc, replace=False, **dbattrs): - """Helper function for registering Python function as a PDFBaseline. This - is required for using Python function as PDFCalculator.baseline. + """Helper function for registering Python function as a PDFBaseline. + This is required for using Python function as + PDFCalculator.baseline. name -- unique string name for registering Python function in the global registry of PDFBaseline types. This will be the @@ -85,7 +86,9 @@ def fshiftedline(x, aline, bline): """ from diffpy.srreal.wraputils import _wrapAsRegisteredUnaryFunction - rv = _wrapAsRegisteredUnaryFunction(PDFBaseline, name, fnc, replace=replace, **dbattrs) + rv = _wrapAsRegisteredUnaryFunction( + PDFBaseline, name, fnc, replace=replace, **dbattrs + ) return rv diff --git a/src/diffpy/srreal/pdfcalculator.py b/src/diffpy/srreal/pdfcalculator.py index e24b3e5..0e7524b 100644 --- a/src/diffpy/srreal/pdfcalculator.py +++ b/src/diffpy/srreal/pdfcalculator.py @@ -86,7 +86,8 @@ def _defineCommonInterface(cls): - """This function defines shared properties of PDF calculator classes.""" + """This function defines shared properties of PDF calculator + classes.""" cls.scale = propertyFromExtDoubleAttr( "scale", @@ -161,10 +162,10 @@ def _defineCommonInterface(cls): ) def _call_kwargs(self, structure=None, **kwargs): - """Calculate PDF for the given structure as an (r, G) tuple. Keyword - arguments can be used to configure calculator attributes, these - override any properties that may be passed from the structure, such as - spdiameter. + """Calculate PDF for the given structure as an (r, G) tuple. + Keyword arguments can be used to configure calculator + attributes, these override any properties that may be passed + from the structure, such as spdiameter. structure -- a structure object to be evaluated. Reuse the last structure when None. diff --git a/src/diffpy/srreal/pdfenvelope.py b/src/diffpy/srreal/pdfenvelope.py index 594e80d..c739517 100644 --- a/src/diffpy/srreal/pdfenvelope.py +++ b/src/diffpy/srreal/pdfenvelope.py @@ -77,8 +77,9 @@ def makePDFEnvelope(name, fnc, replace=False, **dbattrs): - """Helper function for registering Python function as a PDFEnvelope. This - is required for using Python function as PDFCalculator envelope. + """Helper function for registering Python function as a PDFEnvelope. + This is required for using Python function as PDFCalculator + envelope. name -- unique string name for registering Python function in the global registry of PDFEnvelope types. This will be the @@ -115,7 +116,9 @@ def fexpdecay(x, expscale, exptail): """ from diffpy.srreal.wraputils import _wrapAsRegisteredUnaryFunction - rv = _wrapAsRegisteredUnaryFunction(PDFEnvelope, name, fnc, replace=replace, **dbattrs) + rv = _wrapAsRegisteredUnaryFunction( + PDFEnvelope, name, fnc, replace=replace, **dbattrs + ) return rv diff --git a/src/diffpy/srreal/peakwidthmodel.py b/src/diffpy/srreal/peakwidthmodel.py index c588497..7c73e8e 100644 --- a/src/diffpy/srreal/peakwidthmodel.py +++ b/src/diffpy/srreal/peakwidthmodel.py @@ -20,7 +20,12 @@ # exported items -__all__ = ["PeakWidthModel", "ConstantPeakWidth", "DebyeWallerPeakWidth", "JeongPeakWidth"] +__all__ = [ + "PeakWidthModel", + "ConstantPeakWidth", + "DebyeWallerPeakWidth", + "JeongPeakWidth", +] from diffpy.srreal import _final_imports from diffpy.srreal.srreal_ext import ( diff --git a/src/diffpy/srreal/scatteringfactortable.py b/src/diffpy/srreal/scatteringfactortable.py index b98fcb3..9fa232a 100644 --- a/src/diffpy/srreal/scatteringfactortable.py +++ b/src/diffpy/srreal/scatteringfactortable.py @@ -17,7 +17,14 @@ # exported items, these also makes them show in pydoc. -__all__ = ["ScatteringFactorTable", "SFTXray", "SFTElectron", "SFTNeutron", "SFTElectronNumber", "SFAverage"] +__all__ = [ + "ScatteringFactorTable", + "SFTXray", + "SFTElectron", + "SFTNeutron", + "SFTElectronNumber", + "SFAverage", +] from diffpy.srreal.sfaverage import SFAverage from diffpy.srreal.srreal_ext import ( diff --git a/src/diffpy/srreal/sfaverage.py b/src/diffpy/srreal/sfaverage.py index 5a1dde4..d524b0c 100644 --- a/src/diffpy/srreal/sfaverage.py +++ b/src/diffpy/srreal/sfaverage.py @@ -116,7 +116,8 @@ def fromStructure(cls, stru, sftb, q=0): @classmethod def fromComposition(cls, composition, sftb, q=0): - """Calculate average scattering factors from atom concentrations. + """Calculate average scattering factors from atom + concentrations. Parameters ---------- @@ -150,7 +151,11 @@ def fromComposition(cls, composition, sftb, q=0): sfa.f1sum = 0.0 * q sfa.f2sum = 0.0 * q # resolve the lookup table object `tb` - tb = sftb if not isinstance(sftb, str) else ScatteringFactorTable.createByType(sftb) + tb = ( + sftb + if not isinstance(sftb, str) + else ScatteringFactorTable.createByType(sftb) + ) for smbl, cnt in sfa.composition.items(): sfq = tb.lookup(smbl, q) sfa.f1sum += cnt * sfq diff --git a/src/diffpy/srreal/structureadapter.py b/src/diffpy/srreal/structureadapter.py index 3abd19a..a878ab9 100644 --- a/src/diffpy/srreal/structureadapter.py +++ b/src/diffpy/srreal/structureadapter.py @@ -12,8 +12,8 @@ # See LICENSE_DANSE.txt for license information. # ############################################################################## -"""Class StructureAdapter -- adapter of any structure object to the interface -expected by srreal PairQuantity calculators. +"""Class StructureAdapter -- adapter of any structure object to the +interface expected by srreal PairQuantity calculators. Routines: @@ -73,11 +73,11 @@ def createStructureAdapter(stru): def RegisterStructureAdapter(fqname, fnc=None): - """Function decorator that marks it as a converter of specified object type - to StructureAdapter class in diffpy.srreal. The registered structure - object types can be afterwards directly used with calculators in - diffpy.srreal as they would be implicitly converted to the internal - diffpy.srreal structure type. + """Function decorator that marks it as a converter of specified + object type to StructureAdapter class in diffpy.srreal. The + registered structure object types can be afterwards directly used + with calculators in diffpy.srreal as they would be implicitly + converted to the internal diffpy.srreal structure type. fqname -- fully qualified class name for the convertible objects. This is the quoted string included in "str(type(obj))". diff --git a/src/diffpy/srreal/structureconverters.py b/src/diffpy/srreal/structureconverters.py index c9b844d..5f9f6cb 100644 --- a/src/diffpy/srreal/structureconverters.py +++ b/src/diffpy/srreal/structureconverters.py @@ -12,8 +12,8 @@ # See LICENSE.txt for license information. # ############################################################################## -"""Converters from other structure representations in Python to diffpy.srreal -StructureAdapter classes.""" +"""Converters from other structure representations in Python to +diffpy.srreal StructureAdapter classes.""" from diffpy.srreal.srreal_ext import ( AtomicStructureAdapter, @@ -26,8 +26,12 @@ # Converters for Molecule and Crystal from pyobjcryst ------------------------ -RegisterStructureAdapter("pyobjcryst._pyobjcryst.Molecule", convertObjCrystMolecule) -RegisterStructureAdapter("pyobjcryst._pyobjcryst.Crystal", convertObjCrystCrystal) +RegisterStructureAdapter( + "pyobjcryst._pyobjcryst.Molecule", convertObjCrystMolecule +) +RegisterStructureAdapter( + "pyobjcryst._pyobjcryst.Crystal", convertObjCrystCrystal +) # Converter for Structure class from diffpy.structure ------------------------ @@ -65,12 +69,14 @@ class _DiffPyStructureMetadata(object): @staticmethod def hasMetadata(stru): - """True if Structure object carries data in its pdffit attribute.""" + """True if Structure object carries data in its pdffit + attribute.""" rv = hasattr(stru, "pdffit") and bool(stru.pdffit) return rv def _customPQConfig(self, pqobj): - """Apply PDF-related metadata if defined in PDFFit structure format.""" + """Apply PDF-related metadata if defined in PDFFit structure + format.""" pqname = type(pqobj).__name__ if pqname not in ("PDFCalculator", "DebyePDFCalculator"): return @@ -98,7 +104,8 @@ def _customPQConfig(self, pqobj): return def _fetchMetadata(self, stru): - """Copy data from the pdffit attribute of diffpy Structure object. + """Copy data from the pdffit attribute of diffpy Structure + object. stru -- instance of Structure class from diffpy.structure @@ -115,11 +122,15 @@ def _fetchMetadata(self, stru): # end of class _DiffPyStructureMetadata -class DiffPyStructureAtomicAdapter(_DiffPyStructureMetadata, AtomicStructureAdapter): +class DiffPyStructureAtomicAdapter( + _DiffPyStructureMetadata, AtomicStructureAdapter +): pass -class DiffPyStructurePeriodicAdapter(_DiffPyStructureMetadata, PeriodicStructureAdapter): +class DiffPyStructurePeriodicAdapter( + _DiffPyStructureMetadata, PeriodicStructureAdapter +): pass diff --git a/src/diffpy/srreal/wraputils.py b/src/diffpy/srreal/wraputils.py index a026edd..4632215 100644 --- a/src/diffpy/srreal/wraputils.py +++ b/src/diffpy/srreal/wraputils.py @@ -12,7 +12,8 @@ # See LICENSE_DANSE.txt for license information. # ############################################################################## -"""Local utilities helpful for tweaking interfaces to boost python classes.""" +"""Local utilities helpful for tweaking interfaces to boost python +classes.""" import copy @@ -59,10 +60,12 @@ def setattrFromKeywordArguments(obj, **kwargs): return -def _wrapAsRegisteredUnaryFunction(cls, regname, fnc, replace=False, **dbattrs): +def _wrapAsRegisteredUnaryFunction( + cls, regname, fnc, replace=False, **dbattrs +): """Helper function for wrapping Python function as PDFBaseline or - PDFEnvelope functor. Not intended for direct usage, this function is - rather called from makePDFBaseline or makePDFEnvelope wrappers. + PDFEnvelope functor. Not intended for direct usage, this function + is rather called from makePDFBaseline or makePDFEnvelope wrappers. cls -- the functor class for wrapping the Python function regname -- string name for registering the function in the global @@ -94,9 +97,9 @@ def clone(self): return copy.copy(self) def type(self): - """Unique string identifier of this functor type. The string is - used for class registration and as an argument for the createByType - function. + """Unique string identifier of this functor type. The + string is used for class registration and as an argument for + the createByType function. Return string identifier. """ @@ -149,7 +152,9 @@ def _pickle_getstate(self): def _pickle_setstate(self, state): if len(state) != 1: - emsg = "expected 1-item tuple in call to __setstate__, got " + repr(state) + emsg = "expected 1-item tuple in call to __setstate__, got " + repr( + state + ) raise ValueError(emsg) self.__dict__.update(state[0]) return diff --git a/tests/conftest.py b/tests/conftest.py index ac3c222..3e0ed93 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -70,6 +70,8 @@ def has_periodictable(): del periodictable except ImportError: has_periodictable = False - logging.warning("Cannot import periodictable, periodictable tests skipped.") + logging.warning( + "Cannot import periodictable, periodictable tests skipped." + ) return has_periodictable diff --git a/tests/test_bondcalculator.py b/tests/test_bondcalculator.py index 808b639..4b28039 100644 --- a/tests/test_bondcalculator.py +++ b/tests/test_bondcalculator.py @@ -79,7 +79,8 @@ def test_pickling(self): return def test_pickling_derived_structure(self): - """Check pickling of BondCalculator with DerivedStructureAdapter.""" + """Check pickling of BondCalculator with + DerivedStructureAdapter.""" from testutils import DerivedStructureAdapter bdc = self.bdc @@ -134,7 +135,10 @@ def test_sites(self): self.assertEqual(5, numpy.max(bdc.sites0)) self.assertEqual(0, numpy.min(bdc.sites1)) self.assertEqual(5, numpy.max(bdc.sites1)) - dij = [(tuple(d) + (i0, i1)) for d, i0, i1 in zip(bdc.directions, bdc.sites0, bdc.sites1)] + dij = [ + (tuple(d) + (i0, i1)) + for d, i0, i1 in zip(bdc.directions, bdc.sites0, bdc.sites1) + ] self.assertEqual(len(dij), len(set(dij))) bdc.maskAllPairs(False) bdc(self.rutile) @@ -287,7 +291,10 @@ def test_sites(self): self.assertEqual(1, numpy.max(bdc.sites0)) self.assertEqual(0, numpy.min(bdc.sites1)) self.assertEqual(1, numpy.max(bdc.sites1)) - dij = [(tuple(d) + (i0, i1)) for d, i0, i1 in zip(bdc.directions, bdc.sites0, bdc.sites1)] + dij = [ + (tuple(d) + (i0, i1)) + for d, i0, i1 in zip(bdc.directions, bdc.sites0, bdc.sites1) + ] self.assertEqual(len(dij), len(set(dij))) bdc.maskAllPairs(False) bdc(self.rutile) diff --git a/tests/test_bvscalculator.py b/tests/test_bvscalculator.py index c2f3838..f15172f 100644 --- a/tests/test_bvscalculator.py +++ b/tests/test_bvscalculator.py @@ -139,7 +139,8 @@ def test_table_pickling(self): return def test_pickling_derived_structure(self): - """Check pickling of BVSCalculator with DerivedStructureAdapter.""" + """Check pickling of BVSCalculator with + DerivedStructureAdapter.""" from testutils import DerivedStructureAdapter bvc = self.bvc diff --git a/tests/test_debyepdfcalculator.py b/tests/test_debyepdfcalculator.py index 693a7ab..ff160f8 100644 --- a/tests/test_debyepdfcalculator.py +++ b/tests/test_debyepdfcalculator.py @@ -23,7 +23,9 @@ def setUp(self): if not TestDebyePDFCalculator.bucky: TestDebyePDFCalculator.bucky = loadDiffPyStructure("C60bucky.stru") if not TestDebyePDFCalculator.tio2rutile: - TestDebyePDFCalculator.tio2rutile = loadDiffPyStructure("TiO2_rutile-fit.stru") + TestDebyePDFCalculator.tio2rutile = loadDiffPyStructure( + "TiO2_rutile-fit.stru" + ) return # def tearDown(self): @@ -166,7 +168,9 @@ def test_pickling(self): for a in dpdfc._namesOfDoubleAttributes(): self.assertEqual(getattr(dpdfc, a), getattr(dpdfc1, a)) self.assertEqual(13.3, dpdfc1.getEnvelope("sphericalshape").spdiameter) - self.assertEqual(dpdfc._namesOfDoubleAttributes(), dpdfc1._namesOfDoubleAttributes()) + self.assertEqual( + dpdfc._namesOfDoubleAttributes(), dpdfc1._namesOfDoubleAttributes() + ) self.assertEqual(dpdfc.usedenvelopetypes, dpdfc1.usedenvelopetypes) self.assertRaises(RuntimeError, pickle_with_attr, dpdfc, foo="bar") return diff --git a/tests/test_overlapcalculator.py b/tests/test_overlapcalculator.py index 07c0bd9..ce27bd3 100644 --- a/tests/test_overlapcalculator.py +++ b/tests/test_overlapcalculator.py @@ -91,7 +91,9 @@ def test_pickling(self): self.assertEqual(getattr(olc, a), getattr(olc1, a)) self.assertFalse(olc1.getPairMask(1, 2)) self.assertTrue(olc1.getPairMask(0, 0)) - self.assertTrue(numpy.array_equal(olc.sitesquareoverlaps, olc1.sitesquareoverlaps)) + self.assertTrue( + numpy.array_equal(olc.sitesquareoverlaps, olc1.sitesquareoverlaps) + ) self.assertRaises(RuntimeError, pickle_with_attr, olc, foo="bar") return @@ -115,7 +117,8 @@ def test_pickling_artb(self): return def test_pickling_derived_structure(self): - """Check pickling of OverlapCalculator with DerivedStructureAdapter.""" + """Check pickling of OverlapCalculator with + DerivedStructureAdapter.""" from testutils import DerivedStructureAdapter olc = self.olc @@ -140,13 +143,18 @@ def test_parallel(self): ncpu = 4 self.pool = multiprocessing.Pool(processes=ncpu) olc = self.olc - polc = createParallelCalculator(OverlapCalculator(), ncpu, self.pool.imap_unordered) + polc = createParallelCalculator( + OverlapCalculator(), ncpu, self.pool.imap_unordered + ) olc.atomradiitable.fromString("Ti:1.6, O:0.66") polc.atomradiitable = olc.atomradiitable self.assertTrue(numpy.array_equal(olc(self.rutile), polc(self.rutile))) self.assertTrue(olc.totalsquareoverlap > 0.0) self.assertEqual(olc.totalsquareoverlap, polc.totalsquareoverlap) - self.assertEqual(sorted(zip(olc.sites0, olc.sites1)), sorted(zip(polc.sites0, polc.sites1))) + self.assertEqual( + sorted(zip(olc.sites0, olc.sites1)), + sorted(zip(polc.sites0, polc.sites1)), + ) olc.atomradiitable.resetAll() self.assertEqual(0.0, sum(olc(self.rutile))) self.assertEqual(0.0, sum(polc(self.rutile))) @@ -288,7 +296,9 @@ def test_coordinations(self): self.assertFalse(numpy.any(olc.coordinations)) olc.atomradiitable.fromString("Ti:1.6, O:0.66") olc(self.rutile) - self.assertTrue(numpy.array_equal([8, 8, 3, 3, 3, 3], olc.coordinations)) + self.assertTrue( + numpy.array_equal([8, 8, 3, 3, 3, 3], olc.coordinations) + ) return def test_coordinationByTypes(self): @@ -350,7 +360,8 @@ def tearDown(self): return def test_totalsquareoverlap(self): - """Check OverlapCalculator.totalsquareoverlap for ObjCryst crystal.""" + """Check OverlapCalculator.totalsquareoverlap for ObjCryst + crystal.""" olc = self.olc self.assertEqual(0.0, olc.totalsquareoverlap) olc(self.rutile) @@ -361,7 +372,8 @@ def test_totalsquareoverlap(self): return def test_meansquareoverlap(self): - """Check OverlapCalculator.meansquareoverlap for ObjCryst crystal.""" + """Check OverlapCalculator.meansquareoverlap for ObjCryst + crystal.""" olc = self.olc self.assertEqual(0.0, olc.meansquareoverlap) olc(self.rutile) @@ -372,7 +384,8 @@ def test_meansquareoverlap(self): return def test_flipDiffTotal(self): - """Check OverlapCalculator.flipDiffTotal for an ObjCryst crystal.""" + """Check OverlapCalculator.flipDiffTotal for an ObjCryst + crystal.""" olc = self.olc olc(self.rutile) self.assertEqual(0.0, olc.flipDiffTotal(0, 1)) @@ -387,7 +400,8 @@ def test_flipDiffTotal(self): return def test_flipDiffMean(self): - """Check OverlapCalculator.flipDiffMean for an ObjCryst crystal.""" + """Check OverlapCalculator.flipDiffMean for an ObjCryst + crystal.""" olc = self.olc olc(self.rutile) self.assertEqual(0.0, olc.flipDiffMean(0, 1)) @@ -405,7 +419,8 @@ def test_flipDiffMean(self): return def test_getNeighborSites(self): - """Check OverlapCalculator.getNeighborSites for an ObjCryst crystal.""" + """Check OverlapCalculator.getNeighborSites for an ObjCryst + crystal.""" olc = self.olc olc(self.rutile) self.assertEqual(set(), olc.getNeighborSites(0)) @@ -417,7 +432,8 @@ def test_getNeighborSites(self): return def test_coordinations(self): - """Check OverlapCalculator.coordinations for an ObjCryst crystal.""" + """Check OverlapCalculator.coordinations for an ObjCryst + crystal.""" olc = self.olc self.assertEqual(0, len(olc.coordinations)) olc(self.rutile) @@ -444,7 +460,8 @@ def test_coordinationByTypes(self): return def test_neighborhoods(self): - """Check OverlapCalculator.neighborhoods for an ObjCryst crystal.""" + """Check OverlapCalculator.neighborhoods for an ObjCryst + crystal.""" olc = self.olc self.assertEqual([], olc.neighborhoods) olc(self.rutile) diff --git a/tests/test_pairquantity.py b/tests/test_pairquantity.py index 01e3bd9..14335a9 100644 --- a/tests/test_pairquantity.py +++ b/tests/test_pairquantity.py @@ -128,7 +128,8 @@ def test_ticker_override(self): return def test__addPairContribution(self): - """Check Python override of PairQuantity._addPairContribution.""" + """Check Python override of + PairQuantity._addPairContribution.""" pqcnt = PQCounter() self.assertEqual(0, pqcnt(carbonzchain(0))) self.assertEqual(0, pqcnt(carbonzchain(1))) @@ -137,7 +138,8 @@ def test__addPairContribution(self): return def test_optimized_evaluation(self): - """Check OPTIMIZED evaluation in Python-defined calculator class.""" + """Check OPTIMIZED evaluation in Python-defined calculator + class.""" c8 = carbonzchain(8) c9 = carbonzchain(9) pqd = PQDerived() diff --git a/tests/test_parallel.py b/tests/test_parallel.py index 3bc524c..b4b53b1 100644 --- a/tests/test_parallel.py +++ b/tests/test_parallel.py @@ -54,7 +54,9 @@ def test_parallel_evaluatortype(self): self.assertEqual("BASIC", ppdfc.evaluatortype) self.assertEqual("BASIC", pdfc.evaluatortype) ppdfc.evaluatortype = "BASIC" - self.assertRaises(ValueError, setattr, ppdfc, "evaluatortype", "OPTIMIZED") + self.assertRaises( + ValueError, setattr, ppdfc, "evaluatortype", "OPTIMIZED" + ) return def test_parallel_pdf(self): @@ -67,7 +69,9 @@ def test_parallel_pdf(self): r1, g1 = ppdfc1(self.cdse) self.assertTrue(numpy.array_equal(r0, r1)) self.assertTrue(numpy.allclose(g0, g1)) - ppdfc2 = createParallelCalculator(PDFCalculator(), self.ncpu, self.pool.imap_unordered) + ppdfc2 = createParallelCalculator( + PDFCalculator(), self.ncpu, self.pool.imap_unordered + ) r2, g2 = ppdfc2(self.cdse) self.assertTrue(numpy.array_equal(r0, r2)) self.assertTrue(numpy.allclose(g0, g2)) @@ -94,7 +98,9 @@ def test_parallel_bonds(self): pbc1 = createParallelCalculator(BondCalculator(), 3, map) d1 = pbc1(nickel) self.assertTrue(numpy.array_equal(d0, d1)) - pbc2 = createParallelCalculator(BondCalculator(), self.ncpu, self.pool.imap_unordered) + pbc2 = createParallelCalculator( + BondCalculator(), self.ncpu, self.pool.imap_unordered + ) d2 = pbc2(nickel) self.assertTrue(numpy.array_equal(d0, d2)) bc.rmax = pbc1.rmax = pbc2.rmax = 2.5 diff --git a/tests/test_pdfbaseline.py b/tests/test_pdfbaseline.py index d07f688..e9aff06 100644 --- a/tests/test_pdfbaseline.py +++ b/tests/test_pdfbaseline.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -"""Unit tests for the PDFBaseline class from diffpy.srreal.pdfcalculator.""" +"""Unit tests for the PDFBaseline class from +diffpy.srreal.pdfcalculator.""" import pickle @@ -93,8 +94,12 @@ def test_type(self): def test__aliasType(self): """Check PDFBaseline._aliasType.""" self.assertRaises(ValueError, PDFBaseline.createByType, "alias") - self.assertRaises(RuntimeError, PDFBaseline._aliasType, "invalid", "alias") - self.assertRaises(RuntimeError, PDFBaseline._aliasType, "linear", "zero") + self.assertRaises( + RuntimeError, PDFBaseline._aliasType, "invalid", "alias" + ) + self.assertRaises( + RuntimeError, PDFBaseline._aliasType, "linear", "zero" + ) PDFBaseline._aliasType("linear", "alias") bl = PDFBaseline.createByType("alias") self.assertEqual("linear", bl.type()) @@ -104,7 +109,9 @@ def test__aliasType(self): bl1 = PDFBaseline.createByType("alias") self.assertTrue(isinstance(bl1, LinearBaseline)) # no other type can be aliased to the existing name. - self.assertRaises(RuntimeError, PDFBaseline._aliasType, "zero", "alias") + self.assertRaises( + RuntimeError, PDFBaseline._aliasType, "zero", "alias" + ) return def test__deregisterType(self): @@ -118,7 +125,9 @@ def test__deregisterType(self): def test_createByType(self): """Check PDFBaseline.createByType()""" - self.assertRaises(ValueError, PDFBaseline.createByType, "notregistered") + self.assertRaises( + ValueError, PDFBaseline.createByType, "notregistered" + ) return def test_isRegisteredType(self): @@ -136,7 +145,9 @@ def test_getAliasedTypes(self): PDFBaseline._aliasType("linear", "bar") PDFBaseline._aliasType("linear", "linear") PDFBaseline._aliasType("bar", "foo") - self.assertEqual({"bar": "linear", "foo": "linear"}, PDFBaseline.getAliasedTypes()) + self.assertEqual( + {"bar": "linear", "foo": "linear"}, PDFBaseline.getAliasedTypes() + ) return def test_getRegisteredTypes(self): @@ -161,7 +172,9 @@ def test_pickling(self): def test_makePDFBaseline(self): """Check the makePDFBaseline wrapper.""" - pbl = makePDFBaseline("parabolabaseline", parabola_baseline, a=1, b=2, c=3) + pbl = makePDFBaseline( + "parabolabaseline", parabola_baseline, a=1, b=2, c=3 + ) self.assertEqual(3, pbl(0)) self.assertEqual(6, pbl(1)) self.assertEqual(11, pbl(2)) @@ -181,10 +194,28 @@ def test_makePDFBaseline(self): self.assertEqual([7, 3, 28], [pbl4(x) for x in [-2, 0, 5]]) self.assertEqual("bar", pbl4.foo) # fail if this baseline type already exists. - self.assertRaises(RuntimeError, makePDFBaseline, "linear", parabola_baseline, a=1, b=2, c=3) - self.assertRaises(RuntimeError, makePDFBaseline, "parabolabaseline", parabola_baseline, a=1, b=2, c=3) + self.assertRaises( + RuntimeError, + makePDFBaseline, + "linear", + parabola_baseline, + a=1, + b=2, + c=3, + ) + self.assertRaises( + RuntimeError, + makePDFBaseline, + "parabolabaseline", + parabola_baseline, + a=1, + b=2, + c=3, + ) # check replacement of an existing type. - makePDFBaseline("linear", parabola_baseline, replace=True, a=1, b=2, c=4) + makePDFBaseline( + "linear", parabola_baseline, replace=True, a=1, b=2, c=4 + ) pbl4 = PDFBaseline.createByType("linear") self.assertEqual(set(("a", "b", "c")), pbl4._namesOfDoubleAttributes()) self.assertEqual(4, pbl4.c) @@ -196,7 +227,9 @@ def test_makePDFBaseline(self): def test_picking_owned(self): """Verify pickling of PDFBaseline owned by PDF calculators.""" - pbl = makePDFBaseline("parabolabaseline", parabola_baseline, a=1, b=2, c=3) + pbl = makePDFBaseline( + "parabolabaseline", parabola_baseline, a=1, b=2, c=3 + ) pbl.a = 7 pbl.foobar = "asdf" pc = PDFCalculator() diff --git a/tests/test_pdfcalcobjcryst.py b/tests/test_pdfcalcobjcryst.py index 3fd4d4c..3780558 100644 --- a/tests/test_pdfcalcobjcryst.py +++ b/tests/test_pdfcalcobjcryst.py @@ -84,19 +84,25 @@ def setself(**kwtoset): def test_CdSeN(self): """Check PDFCalculator on ObjCryst loaded CIF, neutrons.""" - self._comparePDFs("cdsen", "CdSe_cadmoselite_N.fgr", "CdSe_cadmoselite.cif") + self._comparePDFs( + "cdsen", "CdSe_cadmoselite_N.fgr", "CdSe_cadmoselite.cif" + ) self.assertTrue(self.cdsen_mxnd < 0.01) return def test_CdSeX(self): """Check PDFCalculator on ObjCryst loaded CIF, xrays.""" - self._comparePDFs("cdsex", "CdSe_cadmoselite_X.fgr", "CdSe_cadmoselite.cif") + self._comparePDFs( + "cdsex", "CdSe_cadmoselite_X.fgr", "CdSe_cadmoselite.cif" + ) self.assertTrue(self.cdsex_mxnd < 0.01) return def test_rutileaniso(self): """Check PDFCalculator on ObjCryst loaded anisotropic rutile.""" - self._comparePDFs("rutileaniso", "TiO2_rutile-fit.fgr", "TiO2_rutile-fit.cif") + self._comparePDFs( + "rutileaniso", "TiO2_rutile-fit.fgr", "TiO2_rutile-fit.cif" + ) self.assertTrue(self.rutileaniso_mxnd < 0.057) return diff --git a/tests/test_pdfcalculator.py b/tests/test_pdfcalculator.py index f1c9c38..28b3198 100644 --- a/tests/test_pdfcalculator.py +++ b/tests/test_pdfcalculator.py @@ -252,7 +252,9 @@ def test_pickling(self): for a in pdfc._namesOfDoubleAttributes(): self.assertEqual(getattr(pdfc, a), getattr(pdfc1, a)) self.assertEqual(13.3, pdfc1.getEnvelope("sphericalshape").spdiameter) - self.assertEqual(pdfc._namesOfDoubleAttributes(), pdfc1._namesOfDoubleAttributes()) + self.assertEqual( + pdfc._namesOfDoubleAttributes(), pdfc1._namesOfDoubleAttributes() + ) self.assertEqual(pdfc.usedenvelopetypes, pdfc1.usedenvelopetypes) self.assertRaises(RuntimeError, pickle_with_attr, pdfc, foo="bar") return @@ -269,7 +271,8 @@ def test_mask_pickling(self): return def test_pickling_derived_structure(self): - """Check pickling of PDFCalculator with DerivedStructureAdapter.""" + """Check pickling of PDFCalculator with + DerivedStructureAdapter.""" from testutils import DerivedStructureAdapter pdfc = self.pdfcalc @@ -298,7 +301,9 @@ def test_envelopes(self): self.assertEqual("scale", pc.envelopes[0].type()) pc.envelopes += ("qresolution",) self.assertEqual(("qresolution", "scale"), pc.usedenvelopetypes) - self.assertTrue(all([isinstance(e, PDFEnvelope) for e in pc.envelopes])) + self.assertTrue( + all([isinstance(e, PDFEnvelope) for e in pc.envelopes]) + ) return @@ -349,7 +354,8 @@ def test_fft_conversions(self): return def test_fft_roundtrip(self): - """Check if forward and inverse transformation recover the input.""" + """Check if forward and inverse transformation recover the + input.""" fnipf2 = datafile("Ni-fit.fgr") g0 = numpy.loadtxt(fnipf2, usecols=(1,)) dr0 = 0.01 diff --git a/tests/test_pdfenvelope.py b/tests/test_pdfenvelope.py index 7ea75f4..ff8d95a 100644 --- a/tests/test_pdfenvelope.py +++ b/tests/test_pdfenvelope.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -"""Unit tests for the PDFEnvelope class from diffpy.srreal.pdfcalculator.""" +"""Unit tests for the PDFEnvelope class from +diffpy.srreal.pdfcalculator.""" import pickle @@ -91,7 +92,9 @@ def test_type(self): def test_createByType(self): """Check PDFEnvelope.createByType()""" - self.assertRaises(ValueError, PDFEnvelope.createByType, "notregistered") + self.assertRaises( + ValueError, PDFEnvelope.createByType, "notregistered" + ) return def test_getRegisteredTypes(self): @@ -114,7 +117,9 @@ def test_pickling(self): def test_makePDFEnvelope(self): """Check the makePDFEnvelope wrapper.""" - pbl = makePDFEnvelope("parabolaenvelope", parabola_envelope, a=1, b=2, c=3) + pbl = makePDFEnvelope( + "parabolaenvelope", parabola_envelope, a=1, b=2, c=3 + ) self.assertEqual(3, pbl(0)) self.assertEqual(6, pbl(1)) self.assertEqual(11, pbl(2)) @@ -138,7 +143,9 @@ def test_makePDFEnvelope(self): def test_picking_owned(self): """Verify pickling of envelopes owned by PDF calculators.""" - pbl = makePDFEnvelope("parabolaenvelope", parabola_envelope, a=1, b=2, c=3) + pbl = makePDFEnvelope( + "parabolaenvelope", parabola_envelope, a=1, b=2, c=3 + ) pbl.a = 7 pbl.foobar = "asdf" pc = PDFCalculator() @@ -156,7 +163,10 @@ def test_picking_owned(self): dbpc2 = pickle.loads(pickle.dumps(dbpc)) self.assertEqual(3.5, pc2.scale) self.assertEqual(3.5, dbpc2.scale) - pblcopies = [pc2.getEnvelope("parabolaenvelope"), dbpc2.getEnvelope("parabolaenvelope")] + pblcopies = [ + pc2.getEnvelope("parabolaenvelope"), + dbpc2.getEnvelope("parabolaenvelope"), + ] for pbl2 in pblcopies: self.assertEqual(7, pbl2.a) self.assertEqual("asdf", pbl2.foobar) diff --git a/tests/test_peakprofile.py b/tests/test_peakprofile.py index 9b739c1..dfc59ed 100644 --- a/tests/test_peakprofile.py +++ b/tests/test_peakprofile.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -"""Unit tests for the PeakProfile classes from diffpy.srreal.peakprofile.""" +"""Unit tests for the PeakProfile classes from +diffpy.srreal.peakprofile.""" import pickle @@ -28,7 +29,9 @@ def tearDown(self): def test___init__(self): """Check PeakProfile.__init__()""" self.assertNotEqual(0.0, self.pkgauss.peakprecision) - self.assertEqual(self.pkgauss.peakprecision, self.pkcropped.peakprecision) + self.assertEqual( + self.pkgauss.peakprecision, self.pkcropped.peakprecision + ) self.pkgauss._setDoubleAttr("peakprecision", 0.01) self.assertEqual(0.01, self.pkgauss.peakprecision) return @@ -83,7 +86,8 @@ def test_ticker(self): return def test_ticker_override(self): - """Check method override for PeakProfile.ticker in a derived class.""" + """Check method override for PeakProfile.ticker in a derived + class.""" pkf = MySawTooth() self.assertEqual(0, pkf.tcnt) et0 = pkf.ticker() diff --git a/tests/test_peakwidthmodel.py b/tests/test_peakwidthmodel.py index e6566e9..2b5bd85 100644 --- a/tests/test_peakwidthmodel.py +++ b/tests/test_peakwidthmodel.py @@ -101,7 +101,9 @@ def test_isowidths(self): def test_maxWidth(self): """Check PeakWidthModel.maxWidth()""" - self.assertRaises(RuntimeError, PeakWidthModel().maxWidth, self.tio2adpt, 0, 10) + self.assertRaises( + RuntimeError, PeakWidthModel().maxWidth, self.tio2adpt, 0, 10 + ) self.assertEqual(2.0, self.pwconst.maxWidth(self.tio2adpt, 0, 10)) self.assertEqual(2.0, self.pwconst.maxWidth(self.tio2stru, 0, 10)) return @@ -118,7 +120,8 @@ def test_ticker(self): return def test_ticker_override(self): - """Check PeakWidthModel.ticker override in a Python-derived class.""" + """Check PeakWidthModel.ticker override in a Python-derived + class.""" pwm = MyPWM() self.assertEqual(0, pwm.tcnt) et0 = pwm.ticker() @@ -140,7 +143,9 @@ def test_getRegisteredTypes(self): """Check PeakWidthModel.getRegisteredTypes.""" regtypes = PeakWidthModel.getRegisteredTypes() self.assertTrue(3 <= len(regtypes)) - self.assertTrue(regtypes.issuperset(["constant", "debye-waller", "jeong"])) + self.assertTrue( + regtypes.issuperset(["constant", "debye-waller", "jeong"]) + ) return def test_pickling(self): diff --git a/tests/test_scatteringfactortable.py b/tests/test_scatteringfactortable.py index 3d327ae..097d412 100644 --- a/tests/test_scatteringfactortable.py +++ b/tests/test_scatteringfactortable.py @@ -158,7 +158,8 @@ def test_pickling_derived(self): return def test_derived_create(self): - """Check override of ScatteringFactorTable.create in Python class.""" + """Check override of ScatteringFactorTable.create in Python + class.""" lsft = LocalTable() lsft.setCustomAs("Xy", "Na") lsft2 = lsft.create() @@ -167,7 +168,8 @@ def test_derived_create(self): return def test_derived_clone(self): - """Check override of ScatteringFactorTable.clone in Python class.""" + """Check override of ScatteringFactorTable.clone in Python + class.""" lsft = LocalTable() lsft.setCustomAs("Xy", "Na") lsft2 = lsft.clone() @@ -176,7 +178,8 @@ def test_derived_clone(self): return def test_lookup(self): - """Check ScatteringFactorTable.lookup handling of array arguments.""" + """Check ScatteringFactorTable.lookup handling of array + arguments.""" qa = numpy.linspace(0, 50) qb = numpy.array([(x, 0.0) for x in qa])[:, 0] self.assertTrue(qb.strides > qa.strides) @@ -184,8 +187,16 @@ def test_lookup(self): fmn0 = numpy.array([sftx.lookup("Mn", x) for x in qa]) self.assertTrue(numpy.array_equal(fmn0, sftx.lookup("Mn", qa))) self.assertTrue(numpy.array_equal(fmn0, sftx.lookup("Mn", qb))) - self.assertTrue(numpy.array_equal(fmn0.reshape(5, 10), sftx.lookup("Mn", qa.reshape(5, 10)))) - self.assertTrue(numpy.array_equal(fmn0.reshape(5, 2, 5), sftx.lookup("Mn", qa.reshape(5, 2, 5)))) + self.assertTrue( + numpy.array_equal( + fmn0.reshape(5, 10), sftx.lookup("Mn", qa.reshape(5, 10)) + ) + ) + self.assertTrue( + numpy.array_equal( + fmn0.reshape(5, 2, 5), sftx.lookup("Mn", qa.reshape(5, 2, 5)) + ) + ) self.assertTrue(numpy.array_equal(fmn0, sftx.lookup("Mn", list(qa)))) self.assertRaises(TypeError, sftx.lookup, "Na", "asdf") self.assertRaises(TypeError, sftx.lookup, "Na", {}) diff --git a/tests/test_sfaverage.py b/tests/test_sfaverage.py index 87dd9a1..1171b59 100644 --- a/tests/test_sfaverage.py +++ b/tests/test_sfaverage.py @@ -49,7 +49,9 @@ def test_fromStructure_CdSe(self): self.assertTrue(numpy.array_equal(sfavg3.f2sum, sfavg4.f2sum)) sfavg5 = SFAverage.fromStructure(cdse, "EN", qa) self.assertFalse(numpy.array_equal(sfavg3.f1sum, sfavg5.f1sum)) - self.assertRaises(TypeError, SFAverage.fromStructure, "notastructure", self.sftx) + self.assertRaises( + TypeError, SFAverage.fromStructure, "notastructure", self.sftx + ) self.assertRaises(ValueError, SFAverage.fromStructure, cdse, "invalid") return @@ -89,7 +91,8 @@ def tearDown(self): return def test_from_rutile(self): - """Check SFAverage.fromStructure for pyobjcryst Crystal of rutile.""" + """Check SFAverage.fromStructure for pyobjcryst Crystal of + rutile.""" rutile = loadObjCrystCrystal("rutile.cif") qa = numpy.arange(0, 25, 0.1) sfavg = SFAverage.fromStructure(rutile, self.sftx, qa) diff --git a/tests/test_structureadapter.py b/tests/test_structureadapter.py index 384421f..186e2ba 100644 --- a/tests/test_structureadapter.py +++ b/tests/test_structureadapter.py @@ -74,7 +74,8 @@ def test_createStructureAdapterTypes(self): return def test_createStructureAdapter_int64_occupancy(self): - """Check Structure conversion when occupany is of numpy.int64 type.""" + """Check Structure conversion when occupany is of numpy.int64 + type.""" self.nickel[0].occupancy = numpy.int64(0) self.nickel[1].occupancy = numpy.int64(1) adpt = createStructureAdapter(self.nickel) @@ -90,11 +91,19 @@ def test_pickling(self): self.assertEqual(adpt.countSites(), adpt1.countSites()) self.assertEqual(adpt.totalOccupancy(), adpt1.totalOccupancy()) self.assertEqual(adpt.siteAtomType(1), adpt1.siteAtomType(1)) - self.assertTrue(numpy.array_equal(adpt.siteCartesianPosition(1), adpt1.siteCartesianPosition(1))) + self.assertTrue( + numpy.array_equal( + adpt.siteCartesianPosition(1), adpt1.siteCartesianPosition(1) + ) + ) self.assertEqual(adpt.siteMultiplicity(1), adpt1.siteMultiplicity(1)) self.assertEqual(adpt.siteOccupancy(1), adpt1.siteOccupancy(1)) self.assertTrue(adpt.siteAnisotropy(1) is adpt1.siteAnisotropy(1)) - self.assertTrue(numpy.array_equal(adpt.siteCartesianUij(1), adpt1.siteCartesianUij(1))) + self.assertTrue( + numpy.array_equal( + adpt.siteCartesianUij(1), adpt1.siteCartesianUij(1) + ) + ) return def test_pickle_nonwrapped(self): @@ -251,7 +260,8 @@ def test_nosymmetry(self): return def test_nosymmetry_twice(self): - """Check that second call of nosymmetry returns the same object.""" + """Check that second call of nosymmetry returns the same + object.""" adpt1 = nosymmetry(self.nickel) adpt2 = nosymmetry(adpt1) self.assertTrue(adpt1 is adpt2) @@ -294,10 +304,16 @@ def test_objcryst_adapter(self): self.assertTrue(True is self.rutile.siteAnisotropy(0)) self.assertTrue(True is self.rutile.siteAnisotropy(1)) self.assertTrue( - numpy.allclose(numpy.diag([0.008698, 0.008698, 0.005492]), self.rutile.siteCartesianUij(0)) + numpy.allclose( + numpy.diag([0.008698, 0.008698, 0.005492]), + self.rutile.siteCartesianUij(0), + ) ) self.assertTrue( - numpy.allclose(numpy.diag([0.021733, 0.021733, 0.007707]), self.rutile.siteCartesianUij(1)) + numpy.allclose( + numpy.diag([0.021733, 0.021733, 0.007707]), + self.rutile.siteCartesianUij(1), + ) ) return @@ -334,14 +350,16 @@ def test_siteAtomTypeIndex(self): return def test_siteCartesianPositionIndex(self): - """Check out-of-range arguments in AdptClass.siteCartesianPosition.""" + """Check out-of-range arguments in + AdptClass.siteCartesianPosition.""" cnt = self.adpt.countSites() self.assertRaises(IndexError, self.adpt.siteCartesianPosition, cnt) self.assertRaises(IndexError, self.adpt.siteCartesianPosition, -1) return def test_siteMultiplicityIndex(self): - """Check out-of-range arguments in AdptClass.siteMultiplicity.""" + """Check out-of-range arguments in + AdptClass.siteMultiplicity.""" cnt = self.adpt.countSites() self.assertRaises(IndexError, self.adpt.siteMultiplicity, cnt) self.assertRaises(IndexError, self.adpt.siteMultiplicity, -1) @@ -362,7 +380,8 @@ def test_siteAnisotropyIndex(self): return def test_siteCartesianUijIndex(self): - """Check out-of-range arguments in AdptClass.siteCartesianUij.""" + """Check out-of-range arguments in + AdptClass.siteCartesianUij.""" cnt = self.adpt.countSites() self.assertRaises(IndexError, self.adpt.siteCartesianUij, cnt) self.assertRaises(IndexError, self.adpt.siteCartesianUij, -1) @@ -592,7 +611,14 @@ def test_uij_cartn(self): a.uc13 = 0.013 a.uc23 = 0.023 self.assertTrue( - numpy.array_equal(a.uij_cartn, [[0.01, 0.012, 0.013], [0.012, 0.01, 0.023], [0.013, 0.023, 0.01]]) + numpy.array_equal( + a.uij_cartn, + [ + [0.01, 0.012, 0.013], + [0.012, 0.01, 0.023], + [0.013, 0.023, 0.01], + ], + ) ) self.assertEqual(0.01, a.uc11) self.assertEqual(0.01, a.uc22) diff --git a/tests/testutils.py b/tests/testutils.py index 5f594af..c2991a3 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -142,11 +142,15 @@ class DerivedAtomicStructureAdapter(HasCustomPQConfig, AtomicStructureAdapter): pass -class DerivedPeriodicStructureAdapter(HasCustomPQConfig, PeriodicStructureAdapter): +class DerivedPeriodicStructureAdapter( + HasCustomPQConfig, PeriodicStructureAdapter +): pass -class DerivedCrystalStructureAdapter(HasCustomPQConfig, CrystalStructureAdapter): +class DerivedCrystalStructureAdapter( + HasCustomPQConfig, CrystalStructureAdapter +): pass