Skip to content

Commit

Permalink
Merge pull request #853 from lsst/tickets/DM-39696
Browse files Browse the repository at this point in the history
DM-39696: Minor cleanup of test warnings
  • Loading branch information
timj committed Jun 20, 2023
2 parents a2ef0fb + 6610155 commit c31cead
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 54 deletions.
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/_dataset_existence.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __bool__(self) -> bool:
Returns
-------
exists : `bool
exists : `bool`
Evaluates to `True` if the flags evaluate to either ``KNOWN``
or ``VERIFIED``.
"""
Expand Down
2 changes: 0 additions & 2 deletions python/lsst/daf/butler/registries/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ def _importDatasets(
self,
datasets: Iterable[DatasetRef],
expand: bool = True,
idGenerationMode: DatasetIdGenEnum = DatasetIdGenEnum.UNIQUE,
reuseIds: bool = False,
) -> list[DatasetRef]:
# Docstring inherited from lsst.daf.butler.registry.Registry
raise NotImplementedError()
Expand Down
5 changes: 4 additions & 1 deletion tests/test_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ def runPutGetTest(self, storageClass: StorageClass, datasetTypeName: str) -> But
# Now remove the dataset completely.
butler.pruneDatasets([ref], purge=True, unstore=True)
# Lookup with original args should still fail.
self.assertFalse(butler.exists(*args, collections=this_run))
kwargs = {"collections": this_run}
if isinstance(args[0], DatasetRef):
kwargs = {} # Prevent warning from being issued.
self.assertFalse(butler.exists(*args, **kwargs))
# get() should still fail.
with self.assertRaises(FileNotFoundError):
butler.get(ref)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cliUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,22 @@ def cli(things):
class MWOptionDecoratorTest(unittest.TestCase):
"""Tests for the MWOptionDecorator class."""

test_option = MWOptionDecorator("-t", "--test", multiple=True)
_test_option = MWOptionDecorator("-t", "--test", multiple=True)

def testGetName(self):
"""Test getting the option name from the MWOptionDecorator."""
self.assertEqual(self.test_option.name(), "test")
self.assertEqual(self._test_option.name(), "test")

def testGetOpts(self):
"""Test getting the option flags from the MWOptionDecorator."""
self.assertEqual(self.test_option.opts(), ["-t", "--test"])
self.assertEqual(self._test_option.opts(), ["-t", "--test"])

def testUse(self):
"""Test using the MWOptionDecorator with a command."""
mock = MagicMock()

@click.command()
@self.test_option()
@self._test_option()
def cli(test):
mock(test)

Expand All @@ -271,7 +271,7 @@ def testOverride(self):
mock = MagicMock()

@click.command()
@self.test_option(multiple=False)
@self._test_option(multiple=False)
def cli(test):
mock(test)

Expand Down
61 changes: 16 additions & 45 deletions tests/test_simpleButler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import re
import tempfile
import unittest
import uuid
from typing import Any

try:
Expand All @@ -35,8 +34,17 @@
np = None

import astropy.time
from lsst.daf.butler import Butler, ButlerConfig, CollectionType, DatasetRef, DatasetType, Registry, Timespan
from lsst.daf.butler.registry import ConflictingDefinitionError, RegistryConfig, RegistryDefaults
from lsst.daf.butler import (
Butler,
ButlerConfig,
CollectionType,
DatasetId,
DatasetRef,
DatasetType,
Registry,
Timespan,
)
from lsst.daf.butler.registry import RegistryConfig, RegistryDefaults
from lsst.daf.butler.tests import DatastoreMock
from lsst.daf.butler.tests.utils import makeTestTempDir, removeTestTempDir

Expand All @@ -53,7 +61,6 @@ class SimpleButlerTestCase(unittest.TestCase):
"lsst.daf.butler.registry.datasets.byDimensions.ByDimensionsDatasetRecordStorageManagerUUID"
)
datasetsImportFile = "datasets-uuid.yaml"
datasetsIdType = uuid.UUID

def setUp(self):
self.root = makeTestTempDir(TESTDIR)
Expand All @@ -73,11 +80,7 @@ def makeButler(self, **kwargs: Any) -> Butler:

# have to make a registry first
registryConfig = RegistryConfig(config.get("registry"))
if self.datasetsIdType is int:
with self.assertWarns(FutureWarning):
Registry.createFromConfig(registryConfig)
else:
Registry.createFromConfig(registryConfig)
Registry.createFromConfig(registryConfig)

butler = Butler(config, **kwargs)
DatastoreMock.apply(butler)
Expand Down Expand Up @@ -158,8 +161,8 @@ def testDatasetTransfers(self):
butler2.import_(filename=file.name)
datasets1 = list(butler1.registry.queryDatasets(..., collections=...))
datasets2 = list(butler2.registry.queryDatasets(..., collections=...))
self.assertTrue(all(isinstance(ref.id, self.datasetsIdType) for ref in datasets1))
self.assertTrue(all(isinstance(ref.id, self.datasetsIdType) for ref in datasets2))
self.assertTrue(all(isinstance(ref.id, DatasetId) for ref in datasets1))
self.assertTrue(all(isinstance(ref.id, DatasetId) for ref in datasets2))
self.assertCountEqual(
[self.comparableRef(ref) for ref in datasets1],
[self.comparableRef(ref) for ref in datasets2],
Expand All @@ -169,8 +172,6 @@ def testImportTwice(self):
"""Test exporting dimension records and datasets from a repo and then
importing them all back in again twice.
"""
if self.datasetsIdType is not uuid.UUID:
self.skipTest("This test can only work for UUIDs")
# Import data to play with.
butler1 = self.makeButler(writeable=True)
butler1.import_(filename=os.path.join(TESTDIR, "data", "registry", "base.yaml"))
Expand All @@ -186,39 +187,13 @@ def testImportTwice(self):
butler2.import_(filename=file.name)
datasets1 = list(butler1.registry.queryDatasets(..., collections=...))
datasets2 = list(butler2.registry.queryDatasets(..., collections=...))
self.assertTrue(all(isinstance(ref.id, self.datasetsIdType) for ref in datasets1))
self.assertTrue(all(isinstance(ref.id, self.datasetsIdType) for ref in datasets2))
self.assertTrue(all(isinstance(ref.id, DatasetId) for ref in datasets1))
self.assertTrue(all(isinstance(ref.id, DatasetId) for ref in datasets2))
self.assertCountEqual(
[self.comparableRef(ref) for ref in datasets1],
[self.comparableRef(ref) for ref in datasets2],
)

def testDatasetImportReuseIds(self):
"""Test for import that should preserve dataset IDs.
This test assumes that dataset IDs in datasets YAML are different from
what auto-incremental insert would produce.
"""
if self.datasetsIdType is not int:
self.skipTest("This test can only work for UUIDs")
# Import data to play with.
butler = self.makeButler(writeable=True)
butler.import_(filename=os.path.join(TESTDIR, "data", "registry", "base.yaml"))
filename = os.path.join(TESTDIR, "data", "registry", self.datasetsImportFile)
butler.import_(filename=filename, reuseIds=True)
datasets = list(butler.registry.queryDatasets(..., collections=...))
self.assertTrue(all(isinstance(ref.id, self.datasetsIdType) for ref in datasets))
# IDs are copied from YAML, list needs to be updated if file contents
# is changed.
self.assertCountEqual(
[ref.id for ref in datasets],
[1001, 1002, 1003, 1010, 1020, 1030, 2001, 2002, 2003, 2010, 2020, 2030, 2040],
)

# Try once again, it will raise
with self.assertRaises(ConflictingDefinitionError):
butler.import_(filename=filename, reuseIds=True)

def testCollectionTransfers(self):
"""Test exporting and then importing collections of various types."""
# Populate a registry with some datasets.
Expand Down Expand Up @@ -693,11 +668,7 @@ class SimpleButlerMixedUUIDTestCase(SimpleButlerTestCase):
loads datasets from YAML file with integer IDs.
"""

datasetsManager = (
"lsst.daf.butler.registry.datasets.byDimensions.ByDimensionsDatasetRecordStorageManagerUUID"
)
datasetsImportFile = "datasets.yaml"
datasetsIdType = uuid.UUID


if __name__ == "__main__":
Expand Down

0 comments on commit c31cead

Please sign in to comment.