示例#1
0
    def test_init_output_file(self,rm_mock,isfile_mock):
        isfile_mock.return_value = True
        mdig_config = config.get_config()
        mdig_config.overwrite_flag = False
        model_fn = self.repo.get_models()['lifestage_test']
        model = DispersalModel(model_fn,setup=False)
        i = model.get_instances()[0]
        ac = AnalysisCommand("test")
        self.assertRaises(mdig.OutputFileExistsException, ac.init_output_file, i)
        mdig_config.overwrite_flag = True
        output_file = ac.init_output_file(i)
        self.assertEqual(output_file.index("lifestage_test_region_a_i0"), 0)

        # test with rep
        isfile_mock.return_value = False
        output_file = ac.init_output_file(i, i.replicates[0])
        print output_file
        self.assertEqual(output_file.index("lifestage_test_region_a_i0_rep_0"), 0)
示例#2
0
    def test_init_output_file(self, rm_mock, isfile_mock):
        isfile_mock.return_value = True
        mdig_config = config.get_config()
        mdig_config.overwrite_flag = False
        model_fn = self.repo.get_models()['lifestage_test']
        model = DispersalModel(model_fn, setup=False)
        i = model.get_instances()[0]
        ac = AnalysisCommand("test")
        self.assertRaises(mdig.OutputFileExistsException, ac.init_output_file,
                          i)
        mdig_config.overwrite_flag = True
        output_file = ac.init_output_file(i)
        self.assertEqual(output_file.index("lifestage_test_region_a_i0"), 0)

        # test with rep
        isfile_mock.return_value = False
        output_file = ac.init_output_file(i, i.replicates[0])
        print output_file
        self.assertEqual(output_file.index("lifestage_test_region_a_i0_rep_0"),
                         0)
示例#3
0
 def test_run_command(self, rc_mock):
     model_fn = self.repo.get_models()['lifestage_test']
     model = DispersalModel(model_fn, setup=False)
     i = model.get_instances()[0]
     ac = AnalysisCommand("test")
     # test when there are no times set for when to run command
     self.assertRaises(Exception, ac.run_command, maps=[])
     # test when the times are empty list
     ac.times = []
     output_file = ac.init_output_file(i)
     ac.run_command([])
     self.assertEqual(rc_mock.called, False)
     # test when there are times
     ac.times = [1990]
     rc_mock.called = False
     ac.run_command([])
     self.assertEqual(rc_mock.called, True)
示例#4
0
 def test_run_command(self, rc_mock):
     model_fn = self.repo.get_models()['lifestage_test']
     model = DispersalModel(model_fn,setup=False)
     i = model.get_instances()[0]
     ac = AnalysisCommand("test")
     # test when there are no times set for when to run command
     self.assertRaises(Exception, ac.run_command, maps=[])
     # test when the times are empty list
     ac.times=[]
     output_file = ac.init_output_file(i)
     ac.run_command([])
     self.assertEqual(rc_mock.called,False)
     # test when there are times
     ac.times=[1990]
     rc_mock.called = False
     ac.run_command([])
     self.assertEqual(rc_mock.called,True)
示例#5
0
 def test_insert_output_into_cmd(self):
     model_fn = self.repo.get_models()['lifestage_test']
     model = DispersalModel(model_fn, setup=False)
     i = model.get_instances()[0]
     ac = AnalysisCommand("test")
     # test exception for when no output file initialised
     self.assertRaises(OutputFileNotSetException, ac.insert_output_into_cmd)
     # check normal function works
     output_file = ac.init_output_file(i)
     self.assertEqual(output_file.index("lifestage_test_region_a_"), 0)
     output_cmd = ac.insert_output_into_cmd()
     self.assertEqual(output_cmd, "test >> " + output_file)
     # check that file substitution works
     ac.cmd_string = "test %f"
     output_cmd = ac.insert_output_into_cmd()
     self.assertEqual(output_cmd, "test " + output_file)
     # check that it doesn't replaced escaped %
     ac.cmd_string = "test %%f"
     output_cmd = ac.insert_output_into_cmd()
     self.assertEqual(output_cmd, "test %%f >> " + output_file)
示例#6
0
 def test_insert_output_into_cmd(self):
     model_fn = self.repo.get_models()['lifestage_test']
     model = DispersalModel(model_fn,setup=False)
     i = model.get_instances()[0]
     ac = AnalysisCommand("test")
     # test exception for when no output file initialised
     self.assertRaises(OutputFileNotSetException,ac.insert_output_into_cmd)
     # check normal function works
     output_file = ac.init_output_file(i)
     self.assertEqual(output_file.index("lifestage_test_region_a_"), 0)
     output_cmd = ac.insert_output_into_cmd()
     self.assertEqual(output_cmd, "test >> " + output_file)
     # check that file substitution works 
     ac.cmd_string = "test %f"
     output_cmd = ac.insert_output_into_cmd()
     self.assertEqual(output_cmd, "test " + output_file)
     # check that it doesn't replaced escaped %
     ac.cmd_string = "test %%f"
     output_cmd = ac.insert_output_into_cmd()
     self.assertEqual(output_cmd, "test %%f >> " + output_file)