コード例 #1
0
ファイル: test_json_dict.py プロジェクト: benreynwar/plover
    def test_load_dictionary(self):
        def assertEqual(a, b):
            self.assertEqual(a._dict, b)

        for contents, expected in (
            ('{"S": "a"}'       , {('S', ): 'a'    }),
            ('{"S": "\xc3\xb1"}', {('S', ): u'\xf1'}),
            ('{"S": "\xf1"}'    , {('S', ): u'\xf1'}),
        ):
            assertEqual(load_dictionary(make_dict(contents)), expected)
        
        with self.assertRaises(DictionaryLoaderException):
            load_dictionary(make_dict('foo'))
コード例 #2
0
ファイル: test_json_dict.py プロジェクト: hlieberman/plover
    def test_load_dictionary(self):
        def assertEqual(a, b):
            self.assertEqual(a._dict, b)

        for contents, expected in (
            (u'{"S": "a"}'       , {('S', ): 'a'    }),
            # Default encoding is utf-8.
            (u'{"S": "café"}'.encode('utf-8'), {('S', ): u'café'}),
            # But if that fails, the implementation
            # must automatically retry with latin-1.
            (u'{"S": "café"}'.encode('latin-1'), {('S', ): u'café'}),
        ):
            with make_dict(contents) as filename:
                assertEqual(load_dictionary(filename), expected)

        for contents, exception in (
            # Invalid JSON.
            (u'{"foo", "bar",}', ValueError),
            # Invalid JSON.
            (u'foo', ValueError),
            # Cannot convert to dict.
            (u'"foo"', ValueError),
            # Ditto.
            (u'4.2', TypeError),
        ):
            with make_dict(contents) as filename:
                self.assertRaises(exception, load_dictionary, filename)
コード例 #3
0
ファイル: test_json_dict.py プロジェクト: jeremy-w/plover
    def test_load_dictionary(self):
        def assertEqual(a, b):
            self.assertEqual(a._dict, b)

        for contents, expected in (
            (u'{"S": "a"}', {("S",): "a"}),
            # Default encoding is utf-8.
            (u'{"S": "café"}'.encode("utf-8"), {("S",): u"café"}),
            # But if that fails, the implementation
            # must automatically retry with latin-1.
            (u'{"S": "café"}'.encode("latin-1"), {("S",): u"café"}),
        ):
            assertEqual(load_dictionary(make_dict(contents)), expected)

        with self.assertRaises(DictionaryLoaderException):
            load_dictionary(make_dict("foo"))
コード例 #4
0
ファイル: test_json_dict.py プロジェクト: yonglehou/plover
    def test_load_dictionary(self):
        def assertEqual(a, b):
            self.assertEqual(a._dict, b)

        for contents, expected in (
            (u'{"S": "a"}'.encode('utf-8'), {('S', ): u'a'}),
            # Default encoding is utf-8.
            (u'{"S": "café"}'.encode('utf-8'), {('S', ): u'café'}),
            # But if that fails, the implementation
            # must automatically retry with latin-1.
            (u'{"S": "café"}'.encode('latin-1'), {('S', ): u'café'}),
        ):
            with make_dict(contents) as filename:
                assertEqual(load_dictionary(filename), expected)

        for contents, exception in (
            # Invalid JSON.
            (u'{"foo", "bar",}', ValueError),
            # Invalid JSON.
            (u'foo', ValueError),
            # Cannot convert to dict.
            (u'"foo"', ValueError),
            # Ditto.
            (u'4.2', TypeError),
        ):
            with make_dict(contents.encode('utf-8')) as filename:
                self.assertRaises(exception, load_dictionary, filename)
コード例 #5
0
    def test_load_dictionary(self):
        def assertEqual(a, b):
            self.assertEqual(a._dict, b)

        for contents, expected in (
            ('{"S": "a"}', {
                ('S', ): 'a'
            }),
            ('{"S": "\xc3\xb1"}', {
                ('S', ): u'\xf1'
            }),
            ('{"S": "\xf1"}', {
                ('S', ): u'\xf1'
            }),
        ):
            assertEqual(load_dictionary(make_dict(contents)), expected)

        with self.assertRaises(DictionaryLoaderException):
            load_dictionary(make_dict('foo'))
コード例 #6
0
    def test_load_dictionary(self):
        def assertEqual(a, b):
            self.assertEqual(a._dict, b)

        for contents, expected in (
            (u'{"S": "a"}', {
                ('S', ): 'a'
            }),
                # Default encoding is utf-8.
            (u'{"S": "café"}'.encode('utf-8'), {
                ('S', ): u'café'
            }),
                # But if that fails, the implementation
                # must automatically retry with latin-1.
            (u'{"S": "café"}'.encode('latin-1'), {
                ('S', ): u'café'
            }),
        ):
            assertEqual(load_dictionary(make_dict(contents)), expected)

        with self.assertRaises(DictionaryLoaderException):
            load_dictionary(make_dict('foo'))