Skip to content

Commit

Permalink
Add test that just imports everything.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Jan 7, 2023
1 parent 178e48b commit 5012f53
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This file is part of drp_tasks.
#
# LSST Data Management System
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
# See COPYRIGHT file at the top of the source tree.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.

import importlib.resources
import os.path
import unittest

from lsst.utils import doImport


class ImportTestCase(unittest.TestCase):
"""Test that every file can be imported.
drp_tasks does not import all the task code by default and not
every file will always have a test.
"""

def test_import(self):
self.assertImport("lsst.drp.tasks")

def test_import_script(self):
self.assertImport("lsst.drp.tasks.script")

def test_import_dataFrameActions(self):
self.assertImport("lsst.drp.tasks.dataFrameActions")

def test_import_configurableActions(self):
self.assertImport("lsst.drp.tasks.configurableActions")

def assertImport(self, root_pkg):
for file in importlib.resources.contents(root_pkg):
if not file.endswith(".py"):
continue
if file.startswith("__"):
continue
root, ext = os.path.splitext(file)
module_name = f"{root_pkg}.{root}"
with self.subTest(module=module_name):
try:
doImport(module_name)
except ImportError as e:
raise AssertionError(f"Error importing module {module_name}: {e}") from e


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

0 comments on commit 5012f53

Please sign in to comment.