Esempio n. 1
0
    def test_copy_entire_cache_using_object(self):
        directory_to_copy = os.path.join(self.test_data_path,
                                         'numarray_inputs')
        numpy_directory_containing_expected_data = os.path.join(
            self.test_data_path, 'numpy_inputs')
        output_directory = self.temp_dir

        converter = ConvertNumarrayCacheToNumpyCache()
        converter.execute(directory_to_copy, output_directory)

        self.assert_(
            self._are_directories_same(
                numpy_directory_containing_expected_data, output_directory))

        # Should notice that empty directory is gone.
        rmtree(os.path.join(output_directory, 'a'))
        self.assert_(not self._are_directories_same(
            numpy_directory_containing_expected_data, output_directory))

        # Make them the same again
        converter.execute(directory_to_copy, output_directory)
        # Then change contents of one of the files.
        numpy.array([100]).tofile(os.path.join(output_directory, 'f.li4'))
        self.assert_(not self._are_directories_same(
            numpy_directory_containing_expected_data, output_directory))

        # Make them the same again
        converter.execute(directory_to_copy, output_directory)
        # Add directory in output_directory
        os.mkdir(os.path.join(output_directory, 'new_dir'))
        self.assert_(not self._are_directories_same(
            numpy_directory_containing_expected_data, output_directory))
Esempio n. 2
0
    def test_convert_files(self):
        numarray_file_path = os.path.join(self.test_data_path,
                                          'numarray_inputs',
                                          'do_not_change_me.sometext')
        numpy_file_path = os.path.join(self.test_data_path, 'numpy_inputs',
                                       'do_not_change_me.sometext')

        output_directory = self.temp_dir
        convert = ConvertNumarrayCacheToNumpyCache()

        convert.convert_file(
            os.path.join(self.test_data_path, 'numarray_inputs'),
            'do_not_change_me.sometext', output_directory)
        self.assert_(
            os.path.exists(
                os.path.join(output_directory, 'do_not_change_me.sometext')))

        endian = file_flt_storage.storage_file(
            None)._get_native_endian_file_extension_character()

        convert.convert_file(
            os.path.join(self.test_data_path, 'numarray_inputs'), 'f.Int32',
            output_directory)
        self.assert_(
            os.path.exists(os.path.join(output_directory, 'f.%si4' % endian)))

        convert.convert_file(
            os.path.join(self.test_data_path, 'numarray_inputs'), 'd.Float32',
            output_directory)
        self.assert_(
            os.path.exists(os.path.join(output_directory, 'd.%sf4' % endian)))

        convert.convert_file(
            os.path.join(self.test_data_path, 'numarray_inputs'), 'c.txt',
            output_directory)
        self.assert_(os.path.exists(os.path.join(output_directory, 'c.iS7')))

        # Does the file contain the expected data?
        f = open(os.path.join(output_directory, 'c.iS7'), 'rb')
        actual = f.read()
        f.close()

        f = open(os.path.join(self.test_data_path, 'numpy_inputs', 'c.iS7'),
                 'rb')
        expected = f.read()
        f.close()

        self.assertEqual(expected, actual)