Skip to content

Commit

Permalink
fix bug iterating over dict keys
Browse files Browse the repository at this point in the history
  • Loading branch information
n8pease committed Dec 7, 2020
1 parent 0218c7a commit 483f3ef
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/lsst/obs/base/script/ingestRaws.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def ingestRaws(repo, locations, regex, output_run, config=None, config_file=None
output_run : `str`
The path to the location, the run, where datasets should be put.
config : `dict` [`str`, `str`] or `None`
Key-vaule pairs to apply as overrides to the ingest config.
Key-value pairs to apply as overrides to the ingest config.
config_file : `str` or `None`
Path to a config file that contains overrides to the ingest config.
transfer : `str` or None
Expand All @@ -65,7 +65,7 @@ def ingestRaws(repo, locations, regex, output_run, config=None, config_file=None
if config_file is not None:
configOverrides.addFileOverride(config_file)
if config is not None:
for name, value in config:
for name, value in config.items():
configOverrides.addValueOverride(name, value)
configOverrides.applyTo(ingestConfig)
ingester = TaskClass(config=ingestConfig, butler=butler)
Expand Down
44 changes: 44 additions & 0 deletions tests/test_cliCmdTestIngest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@

import unittest

from lsst.daf.butler import Butler
from lsst.daf.butler.cli.butler import cli as butlerCli
from lsst.daf.butler.cli.utils import clickResultMsg, LogCliRunner
from lsst.daf.butler.tests import CliCmdTestBase
from lsst.obs.base.cli.cmd import ingest_raws
from lsst.obs.base.cli.cmd.commands import fits_re
from lsst.obs.base.ingest import RawIngestConfig
import lsst.obs.base


class IngestRawsTestCase(CliCmdTestBase, unittest.TestCase):
Expand Down Expand Up @@ -105,5 +110,44 @@ def test_locations(self):
locations=("in/directory/", "in/another/dir/", "other/file.fits")))


class PatchRawIngestTask(lsst.obs.base.RawIngestTask):

init_args = []

def __init__(self, *args, **kwargs):
self.init_args.append((args, kwargs))
super().__init__(*args, **kwargs)

def run(self, *args, **kwargs):
pass


class RawIngestMockTest(unittest.TestCase):

def setUp(self):
self.runner = LogCliRunner()

def test(self):
"""Verify config gets applied properly."""
with self.runner.isolated_filesystem():
result = self.runner.invoke(butlerCli, ["create", "repo"])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
with unittest.mock.patch("lsst.obs.base.RawIngestTask", new=PatchRawIngestTask) as mock:
# call and override the name parameter of the config
result = self.runner.invoke(butlerCli, ["ingest-raws", "repo", "resources",
"--config", "transfer=hardlink"])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
# Verify the mock class was initialized exactly once:
self.assertEqual(len(mock.init_args), 1)
# Verify that the task was initialized with a 'butler' kwarg
# that received a butler instance:
self.assertIsInstance(mock.init_args[0][1]["butler"], Butler)
# Verify that the task was initialized with a 'config' kwarg
# that received an expected config:
expectedConfig = RawIngestConfig()
expectedConfig.update(transfer="hardlink")
self.assertEqual(mock.init_args[0][1]["config"], expectedConfig)


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

0 comments on commit 483f3ef

Please sign in to comment.