Exemplo n.º 1
0
    def test_load_cdb(self):
        """Load a database from disk and check it
        """

        # test failing to load a cdb that doesn't exist
        cdb_path = "testing/data/not_there.cdb"
        cdb = cinemasci.new("cdb", {"path": cdb_path})
        self.assertFalse(cdb.read_data_from_file())

        # testing a single extract database
        cdb_path = "testing/data/sphere.cdb"
        cdb = cinemasci.new("cdb", {"path": cdb_path})
        self.assertTrue(cdb.read_data_from_file())
        cdb.set_extract_parameter_names(["FILE"])

        # testing queries
        self.assertTrue(cdb.parameter_exists("theta"))
        self.assertFalse(cdb.parameter_exists("nothing"))
        self.assertTrue(cdb.extract_parameter_exists("FILE"))
        self.assertFalse(cdb.extract_parameter_exists("FILE_NONE"))

        # test the same query with parameters in different order
        extract = cdb.get_extracts({"theta": "0", "phi": "36"})
        self.assertEqual(extract, ["testing/data/sphere.cdb/image/36/0.png"])
        extract = cdb.get_extracts({"phi": "36", "theta": "0"})
        self.assertEqual(extract, ["testing/data/sphere.cdb/image/36/0.png"])

        # test a negative query (doesn't exist)
        extract = cdb.get_extracts({"phi": "96", "theta": "0"})
        self.assertEqual(extract, [])
Exemplo n.º 2
0
    def test_multiple_artifacts(self):
        """Load and test a database with multiple artifacts per parameter list
        """

        # testing a single extract database
        cdb_path = "testing/data/multiple_artifacts.cdb"
        cdb = cinemasci.new("cdb", {"path": cdb_path})
        self.assertTrue(cdb.read_data_from_file())
        cdb.set_extract_parameter_names(["FILE"])
        cdb.set_extract_parameter_names(["FILE2"])

        # testing queries
        self.assertTrue(cdb.parameter_exists("theta"))
        self.assertFalse(cdb.parameter_exists("nothing"))
        self.assertTrue(cdb.extract_parameter_exists("FILE"))
        self.assertFalse(cdb.extract_parameter_exists("FILE_NONE"))

        # test the same query with parameters in different order
        extract = cdb.get_extracts({"theta": "0", "phi": "36"})
        self.assertEqual(extract, [
            "testing/data/multiple_artifacts.cdb/image/36/0.png",
            "testing/data/multiple_artifacts.cdb/image_02/36/0.png"
        ])
        extract = cdb.get_extracts({"phi": "36", "theta": "0"})
        self.assertEqual(extract, [
            "testing/data/multiple_artifacts.cdb/image/36/0.png",
            "testing/data/multiple_artifacts.cdb/image_02/36/0.png"
        ])

        # test a negative query (doesn't exist)
        extract = cdb.get_extracts({"phi": "96", "theta": "0"})
        self.assertEqual(extract, [])
Exemplo n.º 3
0
    def test_null_nan_values(self):
        """Load a database and test a database with NULL and NaN values
        """
        cdb_path = "testing/data/test_values.cdb"
        cdb = cinemasci.new("cdb", {"path": cdb_path})
        self.assertTrue(cdb.read_data_from_file())

        cdb.set_extract_parameter_names(["path"])

        # testing queries
        self.assertTrue(cdb.parameter_exists("time"))
        self.assertTrue(cdb.parameter_exists("phi"))
        self.assertTrue(cdb.parameter_exists("theta"))
        self.assertFalse(cdb.parameter_exists("nothing"))
        self.assertTrue(cdb.extract_parameter_exists("path"))
        self.assertFalse(cdb.extract_parameter_exists("FILE"))

        # test the same query with parameters in different order
        extract = cdb.get_extracts({
            "time": "2.0",
            "phi": "1.0",
            "theta": "1.0"
        })
        self.assertEqual(extract, ["testing/data/test_values.cdb/0002/0000"])
        extract = cdb.get_extracts({"time": "", "phi": "1.0", "theta": "1.0"})
        self.assertEqual(extract, ["testing/data/test_values.cdb/0000/0000"])
        extract = cdb.get_extracts({
            "time": "1.0",
            "phi": "NaN",
            "theta": "1.0"
        })
        self.assertEqual(extract, ["testing/data/test_values.cdb/0001/0000"])
Exemplo n.º 4
0
def verify_cinema_database(viewer, cdb, assetname):
    result = False

    if viewer == "view":
        # this is the default case
        if assetname is None:
            assetname = "FILE"

        db = cinemasci.new("cdb", {"path": cdb})
        db.read_data_from_file()

        if db.parameter_exists(assetname):
            result = True
        else:
            print("")
            print(
                "ERROR: Cinema viewer \'view\' is looking for a column named \'{}\', but the"
                .format(assetname))
            print("       the cinema database \'{}\' doesn't have one.".format(
                cdb))
            print("")
            print(
                "       use \'--assetname <name>\' where <name> is one of these possible values"
            )
            print("       that were found in \'{}\':".format(cdb))
            print("")
            print("           \"" + ' '.join(db.get_parameter_names()) + "\"")
            print("")
    else:
        result = True

    return result
Exemplo n.º 5
0
    def readParameterValues(self, path, selectedParameters):
        cdb = cinemasci.new("cdb", {"path": path})
        cdb.read_data_from_file()
        index2isNumeric = self.determineNumericColumns(path)
        parameterValues = dict()

        for i in selectedParameters:
            if index2isNumeric[i]:
                parameterValues[i] = cdb.getParameterValues(
                    selectedParameters[i])
        return parameterValues
Exemplo n.º 6
0
    def buildParameterKey2FilepathMap(self, path, selectedParameters,
                                      selectedFilepaths):
        self.parameterKey2filepathMap.clear()
        cdb = cinemasci.new("cdb", {"path": path})
        cdb.read_data_from_file()
        mapping = cdb.getFilepathMap(selectedParameters, selectedFilepaths)

        for element in mapping:
            parameterKey = element[0]
            if self.parameterKey2filepathMap.get(parameterKey) == None:
                self.parameterKey2filepathMap[parameterKey] = []
            self.parameterKey2filepathMap[parameterKey] += element[1]
        return
Exemplo n.º 7
0
    def test_write_api(self):
        """Create a database from scratch, and test its output against a known result
        """

        dbname = "test_write_test.cdb"
        cdb_path = os.path.join(TestCDB.scratch_dir, dbname)
        cdb = cinemasci.new("cdb", {"path": cdb_path})
        cdb.initialize()

        # insert entries in an order that tests the cdb's ability to order columns
        # as described in the spec
        id = cdb.add_entry({
            'FILE02': '0002.png',
            'time': '1.0',
            'phi': '10.0',
            'theta': '0.0'
        })
        id = cdb.add_entry({
            'time': '0.0',
            'phi': '0.0',
            'theta': '0.0',
            'FILE': '0000.png'
        })
        id = cdb.add_entry({
            'time': '1.0',
            'phi': '10.0',
            'theta': '0.0',
            'FILE01': '0001.png'
        })
        id = cdb.add_entry({'time': '1.0', 'FILE': '0003.png'})

        # write out the cdb
        cdb.finalize()

        # move the output to a specific name
        target_name = "test_write_api.cdb"
        target_path = os.path.join(TestCDB.scratch_dir, target_name)
        shutil.copytree(cdb_path, target_path)
        # test the result
        self.assertTrue(
            filecmp.cmp(
                os.path.join(TestCDB.gold_dir, target_name,
                             cdb.get_data_filename()),
                os.path.join(TestCDB.scratch_dir, target_name,
                             cdb.get_data_filename())),
            "data.csv files are not the same")

        # delete and compare results to gold
        cdb.delete_entry(id)
        cdb.finalize()

        target_name = "test_delete_api.cdb"
        target_path = os.path.join(TestCDB.scratch_dir, target_name)
        shutil.copytree(cdb_path, target_path)
        # test the result
        self.assertTrue(
            filecmp.cmp(
                os.path.join(TestCDB.gold_dir, target_name,
                             cdb.get_data_filename()),
                os.path.join(TestCDB.scratch_dir, target_name,
                             cdb.get_data_filename())),
            "data.csv files are not the same")
Exemplo n.º 8
0
 def determineNumericColumns(self, path):
     cdb = cinemasci.new("cdb", {"path": path})
     cdb.read_data_from_file()
     return cdb.checkNumericColumns()
Exemplo n.º 9
0
 def readDataBaseHeader(self, path):
     cdb = cinemasci.new("cdb", {"path": path})
     cdb.read_data_from_file()
     return cdb.parameternames