예제 #1
0
    def test_smart_str(self):
        """Test the smart_str function."""
        if six.PY3:
            first_result = b"\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91"
            second_result = b"Ry\xc3\xb6k\xc3\xa4le"
            third_result = b"\xd0\x91"
        else:
            first_result = "\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91"
            second_result = "Ry\xc3\xb6k\xc3\xa4le"
            third_result = "\xd0\x91"

        self.assertEqual(smart_str("ŠĐĆŽćžšđ"), first_result)
        self.assertEqual(smart_str(u"\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111"), first_result)

        # Test does not make sense in Python3
        # self.assertEqual(
        #    smart_str(Exception(u'Ryökäle')), second_result)

        self.assertEqual(smart_str(u"\u0411"), third_result)
        self.assertEqual(smart_str(1), "1")
        self.assertEqual(smart_str(1, strings_only=True), 1)
예제 #2
0
    def test_smart_str(self):
        """Test the smart_str function."""
        if six.PY3:
            first_result = b'\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91'
            second_result = b'Ry\xc3\xb6k\xc3\xa4le'
            third_result = b'\xd0\x91'
        else:
            first_result = '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91'
            second_result = 'Ry\xc3\xb6k\xc3\xa4le'
            third_result = '\xd0\x91'

        self.assertEqual(smart_str('ŠĐĆŽćžšđ'), first_result)
        self.assertEqual(
            smart_str(u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'),
            first_result)

        # Test does not make sense in Python3
        #self.assertEqual(
        #    smart_str(Exception(u'Ryökäle')), second_result)

        self.assertEqual(smart_str(u"\u0411"), third_result)
        self.assertEqual(smart_str(1), '1')
        self.assertEqual(smart_str(1, strings_only=True), 1)
예제 #3
0
파일: __init__.py 프로젝트: zeth/magpy
    def execute(self, *args, **options):
        """
        Try to execute this command.
        If the command raises a
        ``CommandError``, intercept it and print it sensibly to
        stderr.
        """
        show_traceback = options.get('traceback', False)

        try:
            self.stdout = options.get('stdout', sys.stdout)
            self.stderr = options.get('stderr', sys.stderr)

            output = self.handle(*args, **options)
            if output:
                self.stdout.write(output)

        except CommandError as exception:
            if show_traceback:
                traceback.print_exc()
            else:
                self.stderr.write(
                    smart_str(self.style.ERROR('Error: %s\n' % exception)))
            sys.exit(1)