diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..87226211 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +python_files = test*.py diff --git a/src/diffpy/pdfgui/control/pdfguicontrol.py b/src/diffpy/pdfgui/control/pdfguicontrol.py index 15632a0d..d3c07a84 100644 --- a/src/diffpy/pdfgui/control/pdfguicontrol.py +++ b/src/diffpy/pdfgui/control/pdfguicontrol.py @@ -93,7 +93,7 @@ def run(self): def startQueue(self): """start queue manager""" - self.queueManager.setDaemon(True) + self.queueManager.ddaemon = True self.queueManager.start() def checkQueue(self): diff --git a/src/diffpy/pdfgui/gui/aboutdialog.py b/src/diffpy/pdfgui/gui/aboutdialog.py index 51012e01..03de2ced 100644 --- a/src/diffpy/pdfgui/gui/aboutdialog.py +++ b/src/diffpy/pdfgui/gui/aboutdialog.py @@ -21,7 +21,7 @@ import wx.lib.agw.hyperlink from diffpy.pdfgui.gui.pdfguiglobals import iconpath -from diffpy.pdfgui.version import __date__, __version__ +from diffpy.pdfgui.version import __version__, __year__ _acknowledgement = """\ This software was developed by the Billinge-group as part of the Distributed @@ -42,7 +42,7 @@ computer programs for studying nanostructure in crystals, J. Phys.: Condens. Matter 19, 335219 (2007).""" -_copyright = "(c) 2005-{year},".format(year=__date__[:4]) +_copyright = "(c) 2005-{year},".format(year=__year__) _homepage = "https://www.diffpy.org" diff --git a/src/diffpy/pdfgui/gui/extendedplotframe.py b/src/diffpy/pdfgui/gui/extendedplotframe.py index 297a7670..a1a052a8 100644 --- a/src/diffpy/pdfgui/gui/extendedplotframe.py +++ b/src/diffpy/pdfgui/gui/extendedplotframe.py @@ -183,8 +183,11 @@ def insertCurve(self, xData, yData, style): return: internal reference to the newly added curve """ stylestr, properties = self.__translateStyles(style) - curveRef = self.subplot.plot(xData, yData, stylestr, **properties)[0] - self.subplot.legend(**legendBoxProperties()) + if stylestr == "": # blank stylestring throws warning for duplicated information + curveRef = self.subplot.plot(xData, yData, **properties)[0] + else: + curveRef = self.subplot.plot(xData, yData, stylestr, **properties)[0] + self.subplot.legend([], **legendBoxProperties()) # add blank list argument to prevent warning try: self.datalims[curveRef] = (min(xData), max(xData), min(yData), max(yData)) except ValueError: @@ -314,7 +317,7 @@ def __translateStyles(self, style): # not 'points', so line properties are required as well lineStyle = lineStyleDict.get(style["line"], "-") # prefer solid lineWidth = style["width"] - stylestr += lineStyle + # stylestr += lineStyle # no need to add lineStyle to stylestr when in properties properties.update({"color": color, "linestyle": lineStyle, "linewidth": lineWidth}) if "legend" in style: diff --git a/src/diffpy/pdfgui/gui/pdfguiglobals.py b/src/diffpy/pdfgui/gui/pdfguiglobals.py index 96f20538..fc5f5e57 100644 --- a/src/diffpy/pdfgui/gui/pdfguiglobals.py +++ b/src/diffpy/pdfgui/gui/pdfguiglobals.py @@ -17,7 +17,7 @@ import os.path -from pkg_resources import Requirement, resource_filename +from importlib_resources import as_file, files from diffpy.pdfgui.gui import debugoptions @@ -31,14 +31,15 @@ isAltered = False # Resolve APPDATADIR base path to application data files. -_mydir = os.path.abspath(resource_filename(__name__, "")) -_upbasedir = os.path.normpath(_mydir + "/../../..") -_development_mode = os.path.basename(_upbasedir) == "src" and os.path.isfile( - os.path.join(_upbasedir, "../setup.py") -) +with as_file(files(__name__)) as file: + _mydir = os.path.abspath(file) + _upbasedir = os.path.normpath(_mydir + "/../../..") + _development_mode = os.path.basename(_upbasedir) == "src" and os.path.isfile( + os.path.join(_upbasedir, "../setup.py") + ) # Requirement must have egg-info. Do not use in _development_mode. -_req = Requirement.parse("diffpy.pdfgui") +_req = "diffpy.pdfgui" # pavol # APPDATADIR = (os.path.dirname(_upbasedir) if _development_mode @@ -47,9 +48,11 @@ if _development_mode: APPDATADIR = os.path.dirname(_mydir) else: - APPDATADIR = os.path.join(resource_filename(_req, ""), "diffpy/pdfgui") + with as_file(files(_req)) as file: + APPDATADIR = os.path.join(file, "") APPDATADIR = os.path.abspath(APPDATADIR) +print(APPDATADIR) # Location of the HTML manual docMainFile = os.path.join(APPDATADIR, "doc/manual/pdfgui.html") diff --git a/src/diffpy/pdfgui/tests/__init__.py b/src/diffpy/pdfgui/tests/__init__.py index 863e9949..a0a02efa 100644 --- a/src/diffpy/pdfgui/tests/__init__.py +++ b/src/diffpy/pdfgui/tests/__init__.py @@ -38,31 +38,32 @@ def testsuite(pattern=""): from itertools import chain from os.path import dirname - from pkg_resources import resource_filename + from importlib_resources import as_file, files loader = unittest.defaultTestLoader - thisdir = resource_filename(__name__, "") - depth = __name__.count(".") + 1 - topdir = thisdir - for i in range(depth): - topdir = dirname(topdir) - suite_all = loader.discover(thisdir, top_level_dir=topdir) - # always filter the suite by pattern to test-cover the selection code. - suite = unittest.TestSuite() - rx = re.compile(pattern) - tsuites = list(chain.from_iterable(suite_all)) - tsok = all(isinstance(ts, unittest.TestSuite) for ts in tsuites) - if not tsok: # pragma: no cover - return suite_all - tcases = chain.from_iterable(tsuites) - for tc in tcases: - tcwords = tc.id().split(".") - shortname = ".".join(tcwords[-3:]) - if rx.search(shortname): - suite.addTest(tc) - # verify all tests are found for an empty pattern. - assert pattern or suite_all.countTestCases() == suite.countTestCases() - return suite + ref = files(__name__) + with as_file(ref) as thisdir: + depth = __name__.count(".") + 1 + topdir = thisdir + for i in range(depth): + topdir = dirname(topdir) + suite_all = loader.discover(thisdir, top_level_dir=topdir) + # always filter the suite by pattern to test-cover the selection code. + suite = unittest.TestSuite() + rx = re.compile(pattern) + tsuites = list(chain.from_iterable(suite_all)) + tsok = all(isinstance(ts, unittest.TestSuite) for ts in tsuites) + if not tsok: # pragma: no cover + return suite_all + tcases = chain.from_iterable(tsuites) + for tc in tcases: + tcwords = tc.id().split(".") + shortname = ".".join(tcwords[-3:]) + if rx.search(shortname): + suite.addTest(tc) + # verify all tests are found for an empty pattern. + assert pattern or suite_all.countTestCases() == suite.countTestCases() + return suite def test(): diff --git a/src/diffpy/pdfgui/version.py b/src/diffpy/pdfgui/version.py index c7eb817e..f05e9201 100644 --- a/src/diffpy/pdfgui/version.py +++ b/src/diffpy/pdfgui/version.py @@ -19,9 +19,15 @@ # We do not use the other three variables, but can be added back if needed. # __all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"] +# from importlib_resources import files, as_file +import os +import time + # obtain version information -from importlib.metadata import version +from importlib.metadata import distribution, version +# with as_file(distribution("diffpy.pdfgui")) as file: +__year__ = time.ctime(os.path.getctime(distribution("diffpy.pdfgui")._path))[-4:] __version__ = version("diffpy.pdfgui") # End of file