Skip to content

Commit

Permalink
Merge pull request #1378 from dmach/fix-tests-oscrc
Browse files Browse the repository at this point in the history
Fix (lack of) loading oscrc in tests
  • Loading branch information
dmach authored Aug 9, 2023
2 parents b36c210 + 7ad815a commit 391abc2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def tearDown(self):
shutil.rmtree(self.tmpdir)
except:
pass
os.environ.pop("OSC_CONFIG", "")
self.assertTrue(len(EXPECTED_REQUESTS) == 0)

def _get_fixtures_dir(self):
Expand Down
13 changes: 11 additions & 2 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import importlib
import os
import unittest

import osc.conf


FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "conf_fixtures")


class TestConf(unittest.TestCase):
def setUp(self):
# reset the global `config` in preparation for running the tests
Expand All @@ -13,6 +17,9 @@ def tearDown(self):
# reset the global `config` to avoid impacting tests from other classes
importlib.reload(osc.conf)

def _get_fixtures_dir(self):
return FIXTURES_DIR

def test_bool_opts_defaults(self):
config = osc.conf.config
for opt in osc.conf._boolean_opts:
Expand All @@ -28,15 +35,17 @@ def test_int_opts_defaults(self):
self.assertIsInstance(config[opt], int, msg=f"option: '{opt}'")

def test_bool_opts(self):
osc.conf.get_config()
oscrc = os.path.join(self._get_fixtures_dir(), "oscrc")
osc.conf.get_config(override_conffile=oscrc, override_no_keyring=True)
config = osc.conf.config
for opt in osc.conf._boolean_opts:
if opt not in config:
continue
self.assertIsInstance(config[opt], bool, msg=f"option: '{opt}'")

def test_int_opts(self):
osc.conf.get_config()
oscrc = os.path.join(self._get_fixtures_dir(), "oscrc")
osc.conf.get_config(override_conffile=oscrc, override_no_keyring=True)
config = osc.conf.config
for opt in osc.conf._integer_opts:
if opt not in config:
Expand Down
9 changes: 8 additions & 1 deletion tests/test_grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
import osc.grabber as osc_grabber


FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "conf_fixtures")


class TestMirrorGroup(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp(prefix='osc_test')
# reset the global `config` in preparation for running the tests
importlib.reload(osc.conf)
osc.conf.get_config()
oscrc = os.path.join(self._get_fixtures_dir(), "oscrc")
osc.conf.get_config(override_conffile=oscrc, override_no_keyring=True)

def tearDown(self):
# reset the global `config` to avoid impacting tests from other classes
Expand All @@ -22,6 +26,9 @@ def tearDown(self):
except:
pass

def _get_fixtures_dir(self):
return FIXTURES_DIR

def test_invalid_scheme(self):
gr = osc_grabber.OscFileGrabber()
mg = osc_grabber.OscMirrorGroup(gr, ["container://example.com"])
Expand Down

0 comments on commit 391abc2

Please sign in to comment.