Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-11514: Support new pytest #18

Merged
merged 7 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config.log
*.so
*.cfgc
*.pyc
.cache
lib/libbase.*
python/lsst/base/version.py
python/lsst64defs.py
Expand Down
7 changes: 5 additions & 2 deletions python/lsst/base/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
old.update(pkgs) # Include any new packages in the old
old.write("/path/to/packages.pickle")
"""
from future import standard_library
standard_library.install_aliases()
from builtins import object

import os
Expand All @@ -44,6 +42,9 @@

from .versions import getRuntimeVersions

from future import standard_library
standard_library.install_aliases()

__all__ = ["getVersionFromPythonModule", "getPythonPackages", "getEnvironmentPackages", "Packages"]


Expand Down Expand Up @@ -127,6 +128,8 @@ def getPythonPackages():


_eups = None # Singleton Eups object


def getEnvironmentPackages():
"""Provide a dict of products and their versions from the environment

Expand Down
3 changes: 3 additions & 0 deletions python/lsstDebug.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#


#
# Define a class to configure debugging information
#
Expand Down Expand Up @@ -61,8 +62,10 @@ def __setattr__(self, what, value):
"""Set the value of the variable "what" in self.__modname to value"""
self._dict[what] = value


getInfo = Info


def getDebugFrame(debugDisplay, name):
"""
Attempt to extract a frame for displaying a product called `name` from the `debugDisplay` variable.
Expand Down
2 changes: 1 addition & 1 deletion python/lsstcppimport.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from _lsstcppimport import *
from _lsstcppimport import * # noqa F403 F401
6 changes: 3 additions & 3 deletions python/lsstimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def imp_load_module(name, *args):
lsstIdx = [i for i, el in enumerate(pathParts) if el == 'python']
if pathParts[-1] in LIB_EXCEPTION_LIST or (extension in SHARED_LIB_EXTENSION_LIST and
pathParts[-1].startswith('_') and
'lsst' in [pathParts[i+1] for i in lsstIdx]):
'lsst' in [pathParts[i + 1] for i in lsstIdx]):
# Get currently set flags
originalDLFlags = sys.getdlopenflags()
# Set flags
Expand All @@ -110,12 +110,12 @@ def imp_load_module(name, *args):
imp.load_module = imp_load_module

try:
import lsstcppimport
import lsstcppimport # noqa F401
except ImportError:
# The lsstcppimport may have failed because we're inside Scons.
# If we are, then don't worry about it
try:
import SCons.Script
import SCons.Script # noqa F401
# If we're not, then
# a) we will get an ImportError trying to import SCons.Script
# b) and will know that the first ImportError really is a problem
Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
max-line-length = 110
ignore = E133, E226, E228, N802, N803
exclude = __init__.py

[tool:pytest]
addopts = --flake8
3 changes: 2 additions & 1 deletion tests/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
from lsst.sconsUtils import scripts

scripts.BasicSConscript.pybind11(['testModuleImporterLib'])
scripts.BasicSConscript.tests(noBuildList=['testModuleImporterLib.cc'])
scripts.BasicSConscript.tests(noBuildList=['testModuleImporterLib.cc'],
pySingles=['testModuleImporter2.py'], pyList=[])
3 changes: 2 additions & 1 deletion tests/testModuleImporter2.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def testImporter(self):
# Before we import lsst, the functionality to import Python modules from C++ should not work.
self.assertFalse(testModuleImporterLib.doImport("math"))
# ...but after we import lsst (and lsstimport and lsstcppimport), it should.`
import lsst
import lsst # noqa F401
self.assertTrue(testModuleImporterLib.doImport("math"))


if __name__ == "__main__":
unittest.main()
7 changes: 4 additions & 3 deletions tests/packages.py → tests/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
#
from future import standard_library
standard_library.install_aliases()

import os
import unittest
import tempfile

import lsst.base

from future import standard_library
standard_library.install_aliases()


class PackagesTestCase(unittest.TestCase):
"""Tests for package version collection
Expand Down Expand Up @@ -113,5 +113,6 @@ def testPackages(self):
self.assertDictEqual(packages.extra(new), {})
self.assertEqual(len(packages), len(new))


if __name__ == "__main__":
unittest.main()
6 changes: 4 additions & 2 deletions tests/testThreads2.py → tests/test_threads.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@

from past.builtins import long


class ThreadsTestCase(unittest.TestCase):

def testApi(self):
from lsst.base import haveThreads
self.assertIsInstance(haveThreads(), bool)

from lsst.base import setNumThreads
from lsst.base import setNumThreads # noqa F401
# Raises lsst::base::NoThreadsException which is untranslated
# when threading library is missing, this needs fixing!
# self.assertIs(setNumThreads(4), None)

from lsst.base import getNumThreads
from lsst.base import getNumThreads
self.assertIsInstance(getNumThreads(), (int, long))

from lsst.base import disableImplicitThreading
self.assertIsInstance(disableImplicitThreading(), bool)


if __name__ == "__main__":
unittest.main()