Exemplo n.º 1
0
    def test_4(self):
        """test generation of sample directories"""
        myModel = mcTestModels.staticModel()
        statFrw = sf.StaticFramework(myModel)
        mcFw = mf.MonteCarloFramework(statFrw, 5)
        directoriesCreated = True
        for directory in range(1, 6):
            if not os.path.isdir(str(directory)):
                directoriesCreated = False
        self.assertTrue(directoriesCreated)

        for directory in range(1, 6):
            shutil.rmtree(str(directory))

        myModel = mcTestModels.dynamicModel()
        dynFrw = df.DynamicFramework(myModel, 10)
        mcFw = mf.MonteCarloFramework(dynFrw, 5)
        directoriesCreated = True
        for directory in range(1, 6):
            if not os.path.isdir(str(directory)):
                directoriesCreated = False
        self.assertTrue(directoriesCreated)

        for directory in range(1, 6):
            shutil.rmtree(str(directory))
Exemplo n.º 2
0
    def test_5(self):
        """test execution of sections, report, readmap for a static model"""
        myModel = mcTestModels.staticModel()
        statFrw = sf.StaticFramework(myModel)
        mcFw = mf.MonteCarloFramework(statFrw, 5)
        mcFw.setQuiet(True)
        mcFw.run()

        filesInitialCreated = True
        filesPremcCreated = True
        filesPostmcCreated = True

        for sample in range(1, 6):
            nameInit = "mcsi%d.map" % (sample)
            namePre = "premc%d.map" % (sample)
            namePost = "postmc%d.map" % (sample)
            if not os.path.isfile(os.path.join(str(sample), nameInit)):
                filesInitialCreated = False
            if not os.path.isfile(namePre):
                filesPremcCreated = False
            if not os.path.isfile(namePost):
                filesPostmcCreated = False

        self.assertTrue(filesInitialCreated)
        self.assertTrue(filesPremcCreated)
        self.assertTrue(filesPostmcCreated)
 def test_5(self):
     #class StaticPCRasterModel(frameworkMetaClasses.StaticMetaClass):
     #def __init__(self):
     #  pass
     myModel = staticTestModels.Static1()
     staticModelFw = sf.StaticFramework(myModel)
     staticModelFw.run()
 def test_3(self):
     """test execution of initial method"""
     myModel = staticTestModels.T2()
     staticModelFw = sf.StaticFramework(myModel)
     self.assertEqual(myModel.value, 0)
     staticModelFw.run()
     self.assertEqual(myModel.value, 1)
 def test_2(self):
     """test existence of initial method"""
     myModel = staticTestModels.T1()
     try:
         staticModel = sf.StaticFramework(myModel)
     except FrameworkError as e:
         self.assertEqual(
             str(e),
             "Cannot run static framework: Implement either an initial or a run method in the user class"
         )
 def test_4(self):
     """test self.readmap/self.report functionality"""
     myModel = staticTestModels.ReadmapReport()
     staticModelFw = sf.StaticFramework(myModel)
     staticModelFw.run()
     try:
         result = pcraster.readmap("static.map")
         self.failUnless(
             self.mapEquals(result, "plus.Result.map"), "test_4: %s" %
             ("Result and validated result are not the same"))
     except Exception as exception:
         self.failUnless(False, "test4: %s" % (str(exception)))
Exemplo n.º 7
0
 def test_2(self):
     """test existence of added methods and attributes"""
     myModel = mcTestModels.staticModel()
     statFrw = sf.StaticFramework(myModel)
     mcFw = mf.MonteCarloFramework(statFrw, 5)
     self.assertTrue(hasattr(myModel, "nrSamples"))
     self.assertTrue(hasattr(myModel, "_d_firstSampleNumber"))
     self.assertTrue(hasattr(myModel, "_d_lastSampleNumber"))
     self.assertTrue(hasattr(myModel, "_d_currentSampleNumber"))
     self.assertTrue(hasattr(myModel, "_d_inSample"))
     self.assertTrue(hasattr(myModel, "currentSampleNumber"))
     self.assertTrue(hasattr(myModel, "_lastSampleNumber"))
     self.assertTrue(hasattr(myModel, "_firstSampleNumber"))
     self.assertTrue(hasattr(myModel, "_setCurrentSample"))
     self.assertTrue(hasattr(myModel, "_inSample"))
     self.assertTrue(hasattr(myModel, "sampleNumbers"))
     self.assertTrue(hasattr(myModel, "report"))
     self.assertTrue(hasattr(myModel, "readmap"), "todo")
 def test_1(self):
     """test existence of added methods"""
     myModel = staticTestModels.T2()
     staticModel = sf.StaticFramework(myModel)
     self.assert_(hasattr(myModel, "setDebug"))
     self.assert_(hasattr(myModel, "report"))
Exemplo n.º 9
0
    def test_001(self):
        """test requirements of the user model class"""
        staticModel = pfTestModels.StaticWithoutAll()
        staticModelFrw = sf.StaticFramework(staticModel)
        try:
            pfModel = pf.SequentialImportanceResamplingFramework(
                staticModelFrw)
        except fb.FrameworkError as e:
            self.assertEqual(str(e),
                             "Model must be instance of MonteCarloFramework")

        # updateWeight
        staticModel = pfTestModels.StaticWithoutAll()
        staticModelFrw = sf.StaticFramework(staticModel)
        staticMcFrw = mc.MonteCarloFramework(staticModelFrw, 5)
        try:
            pfModel = pf.SequentialImportanceResamplingFramework(staticMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'updateWeight' method"
            )
        try:
            pfModel = pf.ResidualResamplingFramework(staticMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'updateWeight' method"
            )

        dynamicModel = pfTestModels.DynamicWithoutAll()
        dynamicModelFrw = sf.StaticFramework(dynamicModel)
        dynamicMcFrw = mc.MonteCarloFramework(dynamicModelFrw, 5)
        try:
            pfModel = pf.SequentialImportanceResamplingFramework(dynamicMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'updateWeight' method"
            )
        try:
            pfModel = pf.ResidualResamplingFramework(dynamicMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'updateWeight' method"
            )

        # suspend
        staticModel = pfTestModels.StaticWithoutSuspend()
        staticModelFrw = sf.StaticFramework(staticModel)
        staticMcFrw = mc.MonteCarloFramework(staticModelFrw, 5)
        try:
            pfModel = pf.SequentialImportanceResamplingFramework(staticMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'suspend' method"
            )
        try:
            pfModel = pf.ResidualResamplingFramework(staticMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'suspend' method"
            )

        dynamicModel = pfTestModels.DynamicWithoutSuspend()
        dynamicModelFrw = sf.StaticFramework(dynamicModel)
        dynamicMcFrw = mc.MonteCarloFramework(dynamicModelFrw, 5)
        try:
            pfModel = pf.SequentialImportanceResamplingFramework(dynamicMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'suspend' method"
            )
        try:
            pfModel = pf.ResidualResamplingFramework(dynamicMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'suspend' method"
            )

        # resume
        staticModel = pfTestModels.StaticWithoutResume()
        staticModelFrw = sf.StaticFramework(staticModel)
        staticMcFrw = mc.MonteCarloFramework(staticModelFrw, 5)
        try:
            pfModel = pf.SequentialImportanceResamplingFramework(staticMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'resume' method"
            )
        try:
            pfModel = pf.ResidualResamplingFramework(staticMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'resume' method"
            )

        dynamicModel = pfTestModels.DynamicWithoutResume()
        dynamicModelFrw = sf.StaticFramework(dynamicModel)
        dynamicMcFrw = mc.MonteCarloFramework(dynamicModelFrw, 5)
        try:
            pfModel = pf.SequentialImportanceResamplingFramework(dynamicMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'resume' method"
            )
        try:
            pfModel = pf.ResidualResamplingFramework(dynamicMcFrw)
        except fb.FrameworkError as e:
            self.assertEqual(
                str(e),
                "Cannot run particle filter framework: Implement 'resume' method"
            )