Пример #1
0
 def test_unix(self, mock_check, mock_path):
     '''Test build_stata()'s standard behaviour on Unix machines'''
     mock_check.side_effect = fx.make_stata_side_effect('stata-mp')
     # Mock is_in_path() to finds just one executable of Stata
     mock_path.side_effect = fx.make_stata_path_effect('stata-mp')
     env = {'stata_executable': None}
     helpers.standard_test(self,
                           gs.build_stata,
                           'do',
                           env=env,
                           system_mock=mock_check)
Пример #2
0
    def test_windows(self, mock_is_64, mock_check, mock_path):
        '''
        Test that build_stata() behaves correctly on a Windows machine
        when given appropriate inputs. 
        '''
        # i) Non-64-bit Windows without a STATAEXE environment variable
        mock_check.side_effect = fx.make_stata_side_effect('statamp.exe')
        mock_path.side_effect = fx.make_stata_path_effect('statamp.exe')
        mock_is_64.return_value = False

        env = {'user_flavor': None}
        helpers.standard_test(self,
                              gs.build_stata,
                              'do',
                              env=env,
                              system_mock=mock_check)

        # ii) 64-bit Windows without a STATAEXE environment variable
        mock_check.side_effect = fx.make_stata_side_effect('statamp-64.exe')
        mock_path.side_effect = fx.make_stata_path_effect('statamp-64.exe')
        mock_is_64.return_value = True

        helpers.standard_test(self,
                              gs.build_stata,
                              'do',
                              env=env,
                              system_mock=mock_check)

        # ii) Windows with a STATAEXE environment variable
        mock_check.side_effect = fx.make_stata_side_effect(r'%STATAEXE%')
        mock_path.side_effect = fx.make_stata_path_effect(r'%STATAEXE%')

        with mock.patch('%s.os.environ' % path, {'STATAEXE': 'statamp.exe'}):
            helpers.standard_test(self,
                                  gs.build_stata,
                                  'do',
                                  env=env,
                                  system_mock=mock_check)
Пример #3
0
    def test_windows(self, mock_is_64, mock_check, mock_path):
        '''
        Test that build_stata() behaves correctly on a Windows machine
        when given appropriate inputs. 
        '''
        mock_check.side_effect = fx.make_stata_side_effect('StataMP-64.exe')
        mock_path.side_effect = fx.make_stata_path_effect('StataMP-64.exe')
        mock_is_64.return_value = False

        env = {'stata_executable': None}
        helpers.standard_test(self,
                              gs.build_stata,
                              'do',
                              env=env,
                              system_mock=mock_check)
Пример #4
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)
Пример #5
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)