コード例 #1
0
ファイル: test_comparedb3.py プロジェクト: ntouran/armi
    def test_compareDatabaseDuplicate(self):
        """end-to-end test of compareDatabases() on a photocopy database"""
        # build two super-simple H5 files for testing
        o, r = test_reactors.loadTestReactor(TEST_ROOT)

        # create two DBs, identical but for file names
        dbs = []
        for i in range(2):
            # create the tests DB
            dbi = database3.DatabaseInterface(r, o.cs)
            dbi.initDB(fName=self._testMethodName + str(i) + ".h5")
            db = dbi.database

            # validate the file exists, and force it to be readable again
            b = h5py.File(db._fullPath, "r")
            self.assertEqual(list(b.keys()), ["inputs"])
            self.assertEqual(sorted(b["inputs"].keys()),
                             ["blueprints", "geomFile", "settings"])
            b.close()

            # append to lists
            dbs.append(db)

        # end-to-end validation that comparing a photocopy database works
        diffs = compareDatabases(dbs[0]._fullPath, dbs[1]._fullPath)
        self.assertEqual(len(diffs.diffs), 0)
        self.assertEqual(diffs.nDiffs(), 0)
コード例 #2
0
    def setUp(self):
        self.o, self.r = test_reactors.loadTestReactor(TEST_ROOT)
        cs = self.o.cs

        self.dbi = database3.DatabaseInterface(self.r, cs)
        self.dbi.initDB(fName=self._testMethodName + ".h5")
        self.db: db.Database3 = self.dbi.database
        self.stateRetainer = self.r.retainState().__enter__()

        # used to test location-based history. see details below
        self.centralAssemSerialNums = []
        self.centralTopBlockSerialNums = []
コード例 #3
0
ファイル: test_comparedb3.py プロジェクト: ntouran/armi
    def test_compareDatabaseSim(self):
        """end-to-end test of compareDatabases() on very simlar databases"""
        # build two super-simple H5 files for testing
        o, r = test_reactors.loadTestReactor(TEST_ROOT)

        # create two DBs, identical but for file names
        dbs = []
        for nCycles in range(1, 3):
            # build some test data
            days = 100 * nCycles
            cycles = [{
                "step days": [days, days],
                "power fractions": [1, 0.5]
            }] * nCycles
            cs = o.cs.modified(
                newSettings={
                    "nCycles": nCycles,
                    "cycles": cycles,
                    "reloadDBName": "something_fake.h5",
                })

            # create the tests DB
            dbi = database3.DatabaseInterface(r, cs)
            dbi.initDB(fName=self._testMethodName + str(nCycles) + ".h5")
            db = dbi.database

            # populate the db with something
            for cycle, node in ((cycle, node) for cycle in range(nCycles + 1)
                                for node in range(2)):
                r.p.cycle = cycle
                r.p.timeNode = node
                r.p.cycleLength = days * 2
                db.writeToDB(r)

            # validate the file exists, and force it to be readable again
            b = h5py.File(db._fullPath, "r")
            dbKeys = sorted(b.keys())
            self.assertEqual(len(dbKeys), 2 * (nCycles + 1) + 1)
            self.assertIn("inputs", dbKeys)
            self.assertIn("c00n00", dbKeys)
            self.assertEqual(sorted(b["inputs"].keys()),
                             ["blueprints", "geomFile", "settings"])
            b.close()

            # append to lists
            dbs.append(db)

        # end-to-end validation that comparing a photocopy database works
        diffs = compareDatabases(dbs[0]._fullPath, dbs[1]._fullPath)
        self.assertEqual(len(diffs.diffs), 456)
        self.assertEqual(diffs.nDiffs(), 3)
コード例 #4
0
ファイル: test_database3.py プロジェクト: ntouran/armi
    def test_prepRestartRun(self):
        """
        This test is based on the armiRun.yaml case that is loaded during the `setUp`
        above. In that cs, `reloadDBName` is set to 'reloadingDB.h5', `startCycle` = 1,
        and `startNode` = 2. The nonexistent 'reloadingDB.h5' must first be
        created here for this test.
        """
        # first successfully call to prepRestartRun
        o, r = test_reactors.loadTestReactor(TEST_ROOT)
        cs = o.cs
        cs = cs.modified(
            newSettings={
                "nCycles":
                3,
                "cycles": [
                    {
                        "step days": [1000, 1000],
                        "power fractions": [1, 1]
                    },
                    {
                        "step days": [1000, 1000],
                        "power fractions": [1, 1]
                    },
                    {
                        "step days": [1000, 1000],
                        "power fractions": [1, 1]
                    },
                ],
                "reloadDBName":
                "something_fake.h5",
            })

        # create a db based on the cs
        dbi = database3.DatabaseInterface(r, cs)
        dbi.initDB(fName="reloadingDB.h5")
        db = dbi.database

        # populate the db with something
        for cycle, node in ((cycle, node) for cycle in range(3)
                            for node in range(2)):
            r.p.cycle = cycle
            r.p.timeNode = node
            r.p.cycleLength = 2000
            db.writeToDB(r)
        db.close()

        self.dbi.prepRestartRun()

        # now make the cycle histories clash and confirm that an error is thrown
        cs = cs.modified(
            newSettings={
                "cycles": [
                    {
                        "step days": [666, 666],
                        "power fractions": [1, 1]
                    },
                    {
                        "step days": [666, 666],
                        "power fractions": [1, 1]
                    },
                    {
                        "step days": [666, 666],
                        "power fractions": [1, 1]
                    },
                ],
            })

        # create a db based on the cs
        dbi = database3.DatabaseInterface(r, cs)
        dbi.initDB(fName="reloadingDB.h5")
        db = dbi.database

        # populate the db with something
        for cycle, node in ((cycle, node) for cycle in range(3)
                            for node in range(2)):
            r.p.cycle = cycle
            r.p.timeNode = node
            r.p.cycleLength = 2000
            db.writeToDB(r)
        db.close()

        with self.assertRaises(ValueError):
            self.dbi.prepRestartRun()