Example #1
0
 def test_malformed_dakota_and_simple(self):
     """
     Test using the --simple-parser
     """
     gold = read('test_gold/read_from_dakota.gold')
 
     # see note above
     templatepath = 'test_files/read_from_dakota.inp'
     if sys.version_info[0] == 2:
         with open(templatepath,'rt',encoding='utf8') as F:
             temp = F.read().replace(u'{várïåbłę}','{variabe}')
         templatepath = 'test_output/read_from_dakota.inp'
         with open(templatepath,'wt',encoding='utf8') as F:
             F.write(temp)
     
     # dakota style using a file that would break the non dakota.interfacing parser
     
     cmd = ' --no-warn --simple-parser test_files/dakota_malformed_default.1 {0} test_output/dakota.3'.format(templatepath)
     pyprepro._dprepro_cli(shsplit(cmd))
     self.assert_(compare_lines(read('test_output/dakota.3'),gold))
 
     # aprepo style with 3 inputs. NOTE: call dprepro
     cmd = '--no-warn --simple-parser test_files/dakota_malformed_aprepro.1 {0} test_output/dakota.4'.format(templatepath)
     pyprepro._dprepro_cli(shsplit(cmd))
     self.assert_(compare_lines(read('test_output/dakota.4'),gold))
Example #2
0
 def test_json_python(self):
     """
     Tests the --json-include and --python-include of CLI for dprepro and pyprepro plus
     the pyprepro function call. Also test with multiple JSONs to address a prior bug
     """ 
     GOLD = read('test_gold/json_include.gold')
 
     cmd = ('--json-include test_files/json_include_params.json '
            '--python-include test_files/python_include_params.py '
            '--json-include test_files/json_include_params2.json '
            'test_files/json_include.inp test_output/json_include0.inp')
     pyprepro._pyprepro_cli(shsplit(cmd))
     
     # CLI
     self.assert_(compare_lines(GOLD,read('test_output/json_include0.inp')))
     
     # Function
     self.assert_(compare_lines(GOLD,pyprepro.pyprepro('test_files/json_include.inp',
                                                       json_include=['test_files/json_include_params.json',
                                                                     'test_files/json_include_params2.json'],
                                                       python_include='test_files/python_include_params.py')))
 
     cmd = ('--no-warn '
            '--json-include test_files/json_include_params.json '
            '--python-include test_files/python_include_params.py '
            '--json-include test_files/json_include_params2.json '
            'test_files/dakota_aprepro.1 ' # Needs something. This doesn't matter
            'test_files/json_include.inp '
            'test_output/json_include1.inp')
     pyprepro._dprepro_cli(shsplit(cmd))
     self.assert_(compare_lines(GOLD,read('test_output/json_include1.inp')))
Example #3
0
    def test_dakota_params_mode(self):
        """
        Test reading dakota params whether aprepro style or not.
        Also tests the dprepro mode of PARAMFILE INPUT OUTPUT
        """
        gold = read('test_gold/read_from_dakota.gold')
    
        # A note on this test. Inside the template file is "{várïåbłę}". If run
        # with python2, that variable name will be fixed via the dprepro parser
        # BUT there is no easy way to fix it within the "read_from_dakota.inp"
        # template. Therefore, we instead make a modify the template
        # ahead of time and store it in the output when using python2
      
        templatepath = 'test_files/read_from_dakota.inp'
        if sys.version_info[0] == 2:
            with open(templatepath,'rt',encoding='utf8') as F:
                temp = F.read().replace(u'{várïåbłę}','{variabe}')
            templatepath = 'test_output/read_from_dakota.inp'
            with open(templatepath,'wt',encoding='utf8') as F:
                F.write(temp)

        ###### NOTE: DPREPRO

        # dakota style with 3 inputs. NOTE: call dprepro
        cmd = ' --no-warn test_files/dakota_default.1 {0} test_output/dakota.1'.format(templatepath)
        pyprepro._dprepro_cli(shsplit(cmd))
        self.assert_(compare_lines(read('test_output/dakota.1'),gold))
    
        # aprepo style with 3 inputs. NOTE: call dprepro
        cmd = '--no-warn test_files/dakota_aprepro.1 {0} test_output/dakota.2'.format(templatepath)
        pyprepro._dprepro_cli(shsplit(cmd))
        self.assert_(compare_lines(read('test_output/dakota.2'),gold))
Example #4
0
 def test_dakota_interfacing(self):
     """Test dakota.interfacing capabilities when it is present"""
     try:
         import dakota.interfacing as di
     except ImportError:
         sys.stderr.write("Skipping tests for dakota.interfacing because it could not be imported.\n")
         return
     gold = read('test_gold/dprepro_di.gold')
     cmd = '--no-warn test_files/dakota_default.1 test_files/dprepro_di.inp test_output/dakota.3'
     pyprepro._dprepro_cli(shsplit(cmd))
     self.assert_(compare_lines(read('test_output/dakota.3'),gold))
Example #5
0
 def test_json(self):
     """
     Tests the --json-include of CLI for dprepro and pyprepro plus
     the pyprepro function call
     """ 
     GOLD = read('test_gold/json_include.gold')
 
     cmd = '--json-include test_files/json_include_params.json test_files/json_include.inp test_output/json_include0.inp'
     pyprepro._pyprepro_cli(shsplit(cmd))
     self.assert_(compare_lines(GOLD,read('test_output/json_include0.inp')))
     self.assert_(compare_lines(GOLD,pyprepro.pyprepro('test_files/json_include.inp',json_include='test_files/json_include_params.json')))
 
     cmd = '--no-warn --json-include test_files/json_include_params.json test_files/dakota_aprepro.1 test_files/json_include.inp test_output/json_include1.inp'
     pyprepro._dprepro_cli(shsplit(cmd))
     self.assert_(compare_lines(GOLD,read('test_output/json_include1.inp')))