from __future__ import unicode_literals

import shcol
import unittest

class TestColumnize(unittest.TestCase):
    def _columnize(self, *args, **kwargs):
        return shcol.columnize(*args, **kwargs)

    def _join(self, items, spacing=2):
        return (spacing * ' ').join(items)

    def test_no_items(self):
        self.assertEqual(self._columnize([]), '')

    def test_spacing(self):
        items = ['foo', 'bar', 'baz']
        for i in range(3):
            self.assertEqual(
                self._columnize(items, spacing=i), self._join(items, i)
            )

    def test_max_line_width(self):
        x, y, z = 30 * 'x', 10 * 'y', 15 * 'z'
        items = [x, y, z]
        self.assertEqual(
            self._columnize(items), self._join([x, y, z])
        )
        self.assertEqual(
            self._columnize(items, max_line_width=50),
            '%s\n%s' % (self._join([x, z]), y)
        )
        self.assertEqual(
            self._columnize(items, max_line_width=45), '\n'.join([x, y, z])
        )


if __name__ == '__main__':
    unittest.main()

@@ -1,8 +1,55 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0A
 from __f
@@ -81,16 +81,47 @@
 terals%0A%0A
+import functools%0Aimport locale%0A
 import s
@@ -142,16 +142,17 @@
 ittest%0A%0A
+%0A
 class Te
@@ -354,24 +354,453 @@
 oin(items)%0A%0A
+    def _sorted(self, items, locale_to_use=None):%0A        if locale_to_use is None:%0A            return sorted(items)%0A        old_locale = locale.getlocale(locale.LC_COLLATE)%0A        sortkey = functools.cmp_to_key(locale.strcoll)%0A        try:%0A            locale.setlocale(locale.LC_COLLATE, locale_to_use)%0A            return sorted(items, key=sortkey)%0A        finally:%0A            locale.setlocale(locale.LC_COLLATE, old_locale)%0A%0A
     def test
@@ -1530,16 +1530,501 @@
      )%0A%0A
+    def test_sort_items(self):%0A        items = %5B'spam', 'ham', 'egg', 'foo', 'bar', 'baz'%5D%0A        self.assertEqual(%0A            self._columnize(items, sort_items=True),%0A            self._join(self._sorted(items))%0A        )%0A        items = %5B'spam', 'h%C3%A4m', 'egg', 'sp%C3%A4m', 'ham', '%C3%A4gg'%5D%0A        german_locale = ('de_DE', 'UTF-8')%0A        self.assertEqual(%0A            self._columnize(items, sort_items=True),%0A            self._join(self._sorted(items, german_locale))%0A        )%0A        %0A
 %0Aif __na
@@ -2061,10 +2061,21 @@
 st.main(
+verbosity=2
 )%0A

Add tests for `sort_items`.