示例#1
0
    def test_unavailable_executable(self, mock_check):
        '''
        Test build_stata()'s behaviour when a Stata executable that 
        isn't recognised is specified. 
        '''
        mock_check.side_effect = fx.make_stata_side_effect('stata-mp')

        env = {'stata_executable': 'stata-se'}
        with self.assertRaises(ExecCallError):
            gs.build_stata(target='./build/stata.dta',
                           source='./input/stata_test_script.do',
                           env=env)
示例#2
0
def run_test(script, log):
    '''Run a test and append results to log.'''
    gs.build_stata(source=script, target=log, env={'user_flavor': None})
    log_dir = os.path.dirname(log)

    # Read the log for the script
    script_log = '%s/sconscript.log' % log_dir
    log_contents = open(script_log, 'rU').read()

    # Add log for individual script to the master log
    with open(log, 'ab') as f:
        f.write(log_contents)

    os.remove(script_log)
示例#3
0
    def test_other_platform(self, mock_check, mock_path):
        '''
        Test build_stata()'s standard behaviour on a non-Unix,
        non-win32 machine.
        '''
        mock_check.side_effect = fx.make_stata_side_effect('stata-mp')
        mock_path.side_effect = fx.make_stata_path_effect('stata-mp')

        # build_stata() will fail to define a command irrespective of
        # whether a stata_executable is specified
        env = {'stata_executable': 'stata-mp'}
        with self.assertRaises(NameError):
            gs.build_stata(target='./test_output.txt',
                           source='./test_script.do',
                           env=env)

        env = {'stata_executable': None}
        with self.assertRaises(NameError):
            gs.build_stata(target='./test_output.txt',
                           source='./test_script.do',
                           env=env)
示例#4
0
    def test_no_executable_in_path(self, mock_check, mock_path):
        '''
        Test build_stata()'s behaviour when there are no valid Stata
        executables in the user's path variable
        '''
        # We mock the system to not find any executable in the path.
        mock_check.side_effect = fx.make_stata_side_effect('')
        mock_path.side_effect = fx.make_stata_path_effect('')

        env = {'stata_executable': None}
        with helpers.platform_patch('darwin',
                                    path), self.assertRaises(ExecCallError):
            gs.build_stata(target='./test_output.txt',
                           source='./test_script.do',
                           env=env)

        with helpers.platform_patch('win32',
                                    path), self.assertRaises(ExecCallError):
            gs.build_stata(target='./test_output.txt',
                           source='./test_script.do',
                           env=env)
示例#5
0
 def test_bad_stata_executable(self):
     env = {'stata_executable': 'bad_stata_executable'}
     with self.assertRaises(ExecCallError):
         gs.build_stata(target='./test_output.txt',
                        source='./test_script.do',
                        env=env)
示例#6
0
 def test_bad_user_executable(self):
     env = {'user_flavor': 'bad_user_executable'}
     with self.assertRaises(BadExecutableError):
         gs.build_stata(target='./test_output.txt',
                        source='./test_script.do',
                        env=env)
示例#7
0
if os.path.isdir(OutDir):
    shutil.rmtree(OutDir)
os.mkdir(OutDir)

#Create output subdirectories
os.mkdir(OutDir + 'Analysis/')
os.mkdir(OutDir + 'Lyx/')

#-------------------------------------------

# Build the Paper

# Run Stata Code
try:
    gs.build_stata(source='Code/Analysis/MasterFile.do',
                   target=OutDir + 'Analysis/',
                   env={'user_flavor': None})
except UnboundLocalError:
    print('Error: You must include Stata in your PATH Environment')
    print('See "IMPORTANT NOTE #2" in this script for details')
    print('Exiting...')
    exit()

# Run R Code
# See Comment 3 for exhaustive discussion of this function
gs.build_r(source='Code/Analysis/script.R',
           target=OutDir + 'Analysis/',
           env={'CL_ARG': OutDir + 'Analysis/table.txt'})

#Compile the Paper
gs.build_lyx(source='Code/Lyx/Template.lyx',