def testStringInclude(self): """Using include directives in strings""" # See if include works for absolute path c = Config.fromYaml(f"something: !include {os.path.join(self.configDir, 'testconfig.yaml')}") self.assertEqual(c["something", "comp", "item3"], 3) with self.assertRaises(FileNotFoundError) as cm: Config.fromYaml("something: !include /not/here.yaml") # Test that it really was trying to open the absolute path self.assertIn("'/not/here.yaml'", str(cm.exception))
def testStringYaml(self): """Test that we can create configs from strings""" c = Config.fromYaml(""" testing: hello formatters: calexp: 3""") self.assertEqual(c["formatters", "calexp"], 3) self.assertEqual(c["testing"], "hello")
def testResource(self): c = Config("resource://lsst.daf.butler/configs/datastore.yaml") self.assertIn("datastore", c) # Test that we can include a resource URI yaml = """ toplevel: true resource: !include resource://lsst.daf.butler/configs/datastore.yaml """ c = Config.fromYaml(yaml) self.assertIn(("resource", "datastore", "cls"), c) # Test that we can include a resource URI with includeConfigs yaml = """ toplevel: true resource: includeConfigs: resource://lsst.daf.butler/configs/datastore.yaml """ c = Config.fromYaml(yaml) self.assertIn(("resource", "datastore", "cls"), c)
def setUpClass(cls): """Create a new butler once only.""" cls.storageClassFactory = StorageClassFactory() cls.root = tempfile.mkdtemp(dir=TESTDIR) dataIds = { "instrument": ["DummyCam"], "physical_filter": ["d-r"], "visit": [42, 43, 44], } # Ensure that we test in a directory that will include some # metacharacters subdir = "sub?#dir" butlerRoot = os.path.join(cls.root, subdir) cls.creatorButler = makeTestRepo(butlerRoot, dataIds, config=Config.fromYaml(BUTLER_CONFIG)) # Create dataset types used by the tests for datasetTypeName, storageClassName in ( ("calexp", "ExposureF"), ("unknown", "ExposureCompositeF"), ("testCatalog", "SourceCatalog"), ("lossless", "ExposureF"), ("uncompressed", "ExposureF"), ("lossy", "ExposureF"), ): storageClass = cls.storageClassFactory.getStorageClass( storageClassName) addDatasetType(cls.creatorButler, datasetTypeName, set(dataIds), storageClass) # And some dataset types that have no dimensions for easy testing for datasetTypeName, storageClassName in ( ("ps", "PropertySet"), ("pl", "PropertyList"), ("pkg", "Packages"), ("config", "Config"), ): storageClass = cls.storageClassFactory.getStorageClass( storageClassName) addDatasetType(cls.creatorButler, datasetTypeName, {}, storageClass)