Skip to content

Commit

Permalink
add unit test for diamond pattern parent registry
Browse files Browse the repository at this point in the history
  • Loading branch information
n8pease committed Jun 29, 2018
1 parent 5f6b54f commit f95819e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/lsst/daf/persistence/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def __init__(self, location):
if os.path.exists(location):
conn = sqlite3.connect(location)
conn.text_factory = str
self.root = location
else:
conn = None
SqlRegistry.__init__(self, conn)
Expand All @@ -441,6 +442,7 @@ def __init__(self, location):
self._config = config
conn = pgsql.connect(host=config["host"], port=config["port"], database=config["database"],
user=config["user"], password=config["password"])
self.root = location
SqlRegistry.__init__(self, conn)

@staticmethod
Expand Down
37 changes: 37 additions & 0 deletions tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,43 @@ def testCreateAggregateAndLoadingAChild(self):
self.assertEqual(objB, butlerD.get('foo', {'val': 2}))


class TestDiamondPattern(unittest.TestCase):
"""A test case for when a butler is created with an output repository and two input repositories that have
a common parent; verifies that the parent's registry is loaded as the parentRegistry of the output
repository.
"""
@staticmethod
def makeRegistry(location, name):
conn = sqlite3.connect(location)
conn.execute("CREATE TABLE {name} (real)".format(name=name))
conn.commit()
conn.close()

def setUp(self):
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestDiamondPattern-")

def tearDown(self):
if os.path.exists(self.testDir):
shutil.rmtree(self.testDir)

def test(self):
repoARoot = os.path.join(self.testDir, 'repoA')
butler = dp.Butler(outputs={'root': repoARoot, 'mapper': ParentRepoTestMapper})
self.makeRegistry(os.path.join(repoARoot, 'registry.sqlite3'), 'repoA')

repoBRoot = os.path.join(self.testDir, 'repoB')
butlerB = dp.Butler(inputs=repoARoot, outputs=repoBRoot)

repoCRoot = os.path.join(self.testDir, 'repoC')
butlerC = dp.Butler(inputs=repoARoot, outputs=repoCRoot)

repoDRoot = os.path.join(self.testDir, 'repoD')
butlerD = dp.Butler(inputs=(repoBRoot, repoCRoot), outputs = repoDRoot)

self.assertEqual(1, len(butlerD._repos.outputs()))
self.assertEqual(os.path.dirname(butlerD._repos.outputs()[0].parentRegistry.root), repoARoot)


class TestMasking(unittest.TestCase):
"""A test case for the repository classes.
Expand Down

0 comments on commit f95819e

Please sign in to comment.