示例#1
0
    def test_gnu_sort_and_the_current_version_of_python_sort_strings_using_byte_value(
            self):
        ''' DUMPER '''
        unsorted_data_list = ['z\n', 'a\n', '\xc3\xb1\n']
        unsorted_data = ''.join(unsorted_data_list)
        sorted_data = ''.join(['a\n', 'z\n', '\xc3\xb1\n'])

        path = make_temp_file(self.tmp_dir, unsorted_data)
        sorted_file = gnu_sort(path, cache_dir=self.tmp_dir)

        assertion_msg = (
            'GNU Sort must sort comparing byte by byte (export '
            'LC_ALL=C) to be faster and consistent with Python 2.')
        if PY3:
            with open(sorted_file, encoding='utf-8') as f:
                assert f.read() == sorted_data, assertion_msg
        else:
            with open(sorted_file) as f:
                assert f.read() == sorted_data, assertion_msg

        os.unlink(path)
        os.unlink(sorted_file)

        python_sort = ''.join(sorted(unsorted_data_list))
        assertion_msg = ('Current Python interpreter must sort strings '
                         'comparing byte by byte, it is important to use the '
                         'same ordering as the one used with GNU Sort. Note '
                         'Python 3 uses unicode by default.')
        assert python_sort == sorted_data, assertion_msg
示例#2
0
    def test_gnu_sort_and_the_current_version_of_python_sort_strings_using_byte_value(
            self):
        ''' DUMPER '''
        unsorted_data_list = ['z\n', 'a\n', '\xc3\xb1\n']
        unsorted_data = ''.join(unsorted_data_list)
        sorted_data = ''.join(['a\n', 'z\n', '\xc3\xb1\n'])

        path = make_temp_file(self.tmp_dir, unsorted_data)
        sorted_file = gnu_sort(path, cache_dir=self.tmp_dir)

        with open(sorted_file) as f:
            eq_(
                f.read(), sorted_data,
                'GNU Sort must sort comparing byte by byte (export '
                'LC_ALL=C) to be faster and consistent with Python 2.')

        os.unlink(path)
        os.unlink(sorted_file)

        python_sort = ''.join(sorted(unsorted_data_list))
        eq_(
            python_sort, sorted_data,
            'Current Python interpreter must sort strings comparing byte by '
            'byte, it is important to use the same ordering as the one used '
            'with GNU Sort. Note Python 3 uses unicode by default.')
示例#3
0
    def test_gnu_sort_can_sort_by_field(self):
        ''' DUMPER '''
        unsorted_data = ''.join(['1,z\n', '2,a\n', '3,\xc3\xb1\n'])
        sorted_data = ''.join(['2,a\n', '1,z\n', '3,\xc3\xb1\n'])

        path = make_temp_file(self.tmp_dir, unsorted_data)
        sorted_file = gnu_sort(path,
                               delimiter=',',
                               fieldspec='2',
                               cache_dir=self.tmp_dir)

        with open(sorted_file) as f:
            eq_(f.read(), sorted_data)

        os.unlink(path)
        os.unlink(sorted_file)
示例#4
0
    def test_gnu_sort_can_sort_by_field(self):
        ''' DUMPER '''
        unsorted_data = ''.join(['1,z\n', '2,a\n', '3,\xc3\xb1\n'])
        sorted_data = ''.join(['2,a\n', '1,z\n', '3,\xc3\xb1\n'])

        path = make_temp_file(self.tmp_dir, unsorted_data)
        sorted_file = gnu_sort(path,
                               delimiter=',',
                               fieldspec='2',
                               cache_dir=self.tmp_dir)

        if PY3:
            with open(sorted_file, encoding='utf-8') as f:
                assert f.read() == sorted_data
        else:
            with open(sorted_file) as f:
                assert f.read() == sorted_data

        os.unlink(path)
        os.unlink(sorted_file)