Esempio n. 1
0
    def test_errors(self):

        # Test passing an unsupported data type (should raise a Type Error)
        with self.assertRaises(TypeError):
            shm.write_list(self.string_variable, 'string', 'strings', 1)

        # Test passing an unsupported data type as a valid one (should raise a Type Error from C)
        # Note also this test also confirms that segments are properly cleaned up after an 
        # exception
        with self.assertRaises(TypeError):
            shm.write_list(self.string_variable, 'int', 'string', 1)

        # Test passing a valid data type with an invalid element (should raise a Type Error from C)
        with self.assertRaises(TypeError):
            shm.write_list(self.mixed_variable, 'int', 'mixed', 1)

        # Test passing a seed used by an existing segment (should raise an OS error from C)
        int_segment = shm.write_list(self.int_variable, 'int', 'ints', 1)
        with self.assertRaises(OSError):
            shm.write_list(self.int_variable, 'int', 'ints', 1)
        shm.deallocate(int_segment[1])

        # Test passing a data frame with unsupported columns (should raise a Type Error)
        bad_data = self.data.copy()
        bad_data.loc[:,'string_var'] = 'Hi'
        with self.assertRaises(TypeError):
            shm.write_frame(bad_data)
Esempio n. 2
0
    def test_stata(self):

        # Test writing to Stata
        stata_segment = shm.write_frame(self.data, info_file = '../temp/test_segment_info.txt')
        rc = os.system('stata-mp test_shm.do')
        self.assertTrue(rc == 0)

        stata_results = pd.read_csv('../temp/results_from_stata.csv')

        # data returned from Stata should be identical to minor precision
        # related issues. Note machine epsilon is about 2.2e-16.

        float_diff = (stata_results['float_var'] - self.data['float_var']).abs()
        self.assertTrue(float_diff.max() < 2.25e-16)

        # there should be no difference in integer variables
        int_diff = (stata_results['int_var'] - self.data['int_var']).abs()
        self.assertTrue(int_diff.max() == 0)