Skip to content

Commit

Permalink
fix some unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jan 14, 2025
1 parent fe55d14 commit ea5e3bb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
4 changes: 2 additions & 2 deletions py/desitemplate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
You should use :command:`desi_update_version` to set the version. This requires
the desiutil_ package.
.. _DESI: http://desi.lbl.gov
.. _Python: http://python.org
.. _DESI: https://www.desi.lbl.gov
.. _Python: https://www.python.org
.. _desiutil: https://github.com/desihub/desiutil
"""
#
Expand Down
31 changes: 1 addition & 30 deletions py/desitemplate/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,5 @@
desitemplate.test
=================
Used to initialize the unit test framework via ``python setup.py test``.
Initialize the unit test framework.
"""
from __future__ import absolute_import

import unittest


def desitemplate_test_suite():
"""Returns unittest.TestSuite of desitemplate tests.
This is factored out separately from runtests() so that it can be used by
``python setup.py test``.
"""
from os.path import dirname
py_dir = dirname(dirname(__file__))
# print(py_dir)
return unittest.defaultTestLoader.discover(py_dir,
top_level_dir=dirname(py_dir))


def runtests():
"""Run all tests in desitemplate.test.test_*.
"""
# Load all TestCase classes from desitemplate/test/test_*.py
tests = desitemplate_test_suite()
# Run them
unittest.TextTestRunner(verbosity=2).run(tests)


if __name__ == "__main__":
runtests()
22 changes: 19 additions & 3 deletions py/desitemplate/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
# -*- coding: utf-8 -*-
"""Test desitemplate.main functions
"""
import contextlib
import io
import unittest
import re
import sys
from unittest.mock import patch
from ..main import main


class TestMain(unittest.TestCase):
"""Test desitemplate.main functions
"""

@classmethod
def setUpClass(cls):
Expand All @@ -24,7 +27,20 @@ def setUp(self):
def tearDown(self):
pass

@patch('sys.argv', ['template_main_script'])
def test_main(self):
"""Test the main() function.
"""
pass
sout = io.StringIO()
with contextlib.redirect_stdout(sout):
self.assertEqual(main(), 0)
self.assertEqual(sout.getvalue(), 'Hello World!\n')

@patch('sys.argv', ['template_main_script', '--verbose'])
def test_main_verbose(self):
"""Test the main() function with -v.
"""
sout = io.StringIO()
with contextlib.redirect_stdout(sout):
self.assertEqual(main(), 0)
self.assertEqual(sout.getvalue(), 'Hello World!\nVerbose selected!\n')
4 changes: 1 addition & 3 deletions py/desitemplate/test/test_top_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
"""
import unittest
import re
import sys
from .. import __version__ as theVersion


class TestTopLevel(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.versionre = re.compile(
r'([0-9]+!)?([0-9]+)(\.[0-9]+)*((a|b|rc|\.post|\.dev)[0-9]+)?')
cls.versionre = re.compile(r'([0-9]+!)?([0-9]+)(\.[0-9]+)*((a|b|rc|\.post|\.dev)[0-9]+)?')

@classmethod
def tearDownClass(cls):
Expand Down

0 comments on commit ea5e3bb

Please sign in to comment.