def test_file_readline_latin1(self):
     ch = GLib.IOChannel(filename=self.testlatin1, mode='r')
     ch.set_encoding('latin1')
     self.assertEqual(ch.get_encoding(), 'latin1')
     self.assertEqual(_unicode(ch.readline()), 'hellø world\n')
     self.assertEqual(ch.readline(), 'second line\n')
     self.assertEqual(ch.readline(), '\n')
     self.assertEqual(_unicode(ch.readline()), 'À demain!')
     ch.shutdown(True)
Exemple #2
0
 def test_file_readline_latin1(self):
     ch = GLib.IOChannel(filename=self.testlatin1, mode='r')
     ch.set_encoding('latin1')
     self.assertEqual(ch.get_encoding(), 'latin1')
     self.assertEqual(_unicode(ch.readline()), 'hellø world\n')
     self.assertEqual(ch.readline(), 'second line\n')
     self.assertEqual(ch.readline(), '\n')
     self.assertEqual(_unicode(ch.readline()), 'À demain!')
     ch.close()
Exemple #3
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(_unicode('aäb'))
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        self.assertEqual(GLib.filename_from_utf8(_unicode('aäb'), 1), b'a')
Exemple #4
0
 def test_file_readlines(self):
     ch = GLib.IOChannel(filename=self.testutf8)
     lines = ch.readlines()
     # Note, this really ought to be 4, but the static bindings add an extra
     # empty one
     self.assertGreaterEqual(len(lines), 4)
     self.assertLessEqual(len(lines), 5)
     self.assertEqual(_unicode(lines[0]), 'hello ♥ world\n')
     self.assertEqual(_unicode(lines[3]), 'À demain!')
     if len(lines) == 4:
         self.assertEqual(lines[4], '')
 def test_file_readlines(self):
     ch = GLib.IOChannel(filename=self.testutf8)
     lines = ch.readlines()
     # Note, this really ought to be 4, but the static bindings add an extra
     # empty one
     self.assertGreaterEqual(len(lines), 4)
     self.assertLessEqual(len(lines), 5)
     self.assertEqual(_unicode(lines[0]), 'hello ♥ world\n')
     self.assertEqual(_unicode(lines[3]), 'À demain!')
     if len(lines) == 4:
         self.assertEqual(lines[4], '')
Exemple #6
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(_unicode('aäb'))
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        self.assertEqual(GLib.filename_from_utf8(_unicode('aäb'), 1), b'a')
Exemple #7
0
 def test_file_readline_utf8(self):
     ch = GLib.IOChannel(filename=self.testutf8)
     self.assertEqual(ch.get_encoding(), 'UTF-8')
     self.assertTrue(ch.get_close_on_unref())
     self.assertEqual(_unicode(ch.readline()), 'hello ♥ world\n')
     self.assertEqual(ch.get_buffer_condition(), GLib.IOCondition.IN)
     self.assertEqual(ch.readline(), 'second line\n')
     self.assertEqual(ch.readline(), '\n')
     self.assertEqual(_unicode(ch.readline()), 'À demain!')
     self.assertEqual(ch.get_buffer_condition(), 0)
     self.assertEqual(ch.readline(), '')
     ch.close()
Exemple #8
0
    def test_utf8(self):
        s = GIMarshallingTests.BoxedStruct()
        s.string_ = "hello"
        self.assertEqual(s.string_, "hello")

        s.string_ = _unicode("hello")
        self.assertEqual(s.string_, _unicode("hello"))

        s.string_ = None
        self.assertEqual(s.string_, None)

        self.assertRaises(TypeError, setattr, s, "string_", 42)
 def test_file_readline_utf8(self):
     ch = GLib.IOChannel(filename=self.testutf8)
     self.assertEqual(ch.get_encoding(), 'UTF-8')
     self.assertTrue(ch.get_close_on_unref())
     self.assertEqual(_unicode(ch.readline()), 'hello ♥ world\n')
     self.assertEqual(ch.get_buffer_condition(), GLib.IOCondition.IN)
     self.assertEqual(ch.readline(), 'second line\n')
     self.assertEqual(ch.readline(), '\n')
     self.assertEqual(_unicode(ch.readline()), 'À demain!')
     self.assertEqual(ch.get_buffer_condition(), 0)
     self.assertEqual(ch.readline(), '')
     ch.shutdown(True)
Exemple #10
0
    def test_utf8(self):
        s = GIMarshallingTests.BoxedStruct()
        s.string_ = "hello"
        self.assertEqual(s.string_, "hello")

        s.string_ = _unicode("hello")
        self.assertEqual(s.string_, _unicode("hello"))

        s.string_ = None
        self.assertEqual(s.string_, None)

        self.assertRaises(TypeError, setattr, s, "string_", 42)
 def test_file_iter(self):
     items = []
     ch = GLib.IOChannel(filename=self.testutf8)
     for item in ch:
         items.append(item)
     self.assertEqual(len(items), 4)
     self.assertEqual(_unicode(items[0]), 'hello ♥ world\n')
     ch.shutdown(True)
Exemple #12
0
    def test_markup_escape_text(self):
        self.assertEqual(GLib.markup_escape_text(_unicode('a&bä')), 'a&bä')
        self.assertEqual(GLib.markup_escape_text(_bytes('a&b\x05')),
                         'a&b')

        # with explicit length argument
        self.assertEqual(GLib.markup_escape_text(_bytes('a\x05\x01\x02'), 2),
                         'a')
Exemple #13
0
 def test_file_iter(self):
     items = []
     ch = GLib.IOChannel(filename=self.testutf8)
     for item in ch:
         items.append(item)
     self.assertEqual(len(items), 4)
     self.assertEqual(_unicode(items[0]), 'hello ♥ world\n')
     ch.close()
    def test_strv(self):
        self.assertEqual(self.get_prop(self.obj, 'some-strv'), [])
        self.set_prop(self.obj, 'some-strv', ['hello', 'world'])
        self.assertEqual(self.get_prop(self.obj, 'some-strv'), ['hello', 'world'])

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', 1)
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', 'foo')
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', [1, 2])
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', ['foo', 1])

        self.assertEqual(self.get_prop(self.obj, 'some-strv'), ['hello', 'world'])

        obj = GIMarshallingTests.PropertiesObject(some_strv=['hello', 'world'])
        self.assertEqual(self.get_prop(obj, 'some-strv'), ['hello', 'world'])

        # unicode on py2
        obj = GIMarshallingTests.PropertiesObject(some_strv=[_unicode('foo')])
        self.assertEqual(self.get_prop(obj, 'some-strv'), [_unicode('foo')])
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv',
                          [_unicode('foo'), 1])
    def test_strv(self):
        self.assertEqual(self.get_prop(self.obj, 'some-strv'), [])
        self.set_prop(self.obj, 'some-strv', ['hello', 'world'])
        self.assertEqual(self.get_prop(self.obj, 'some-strv'), ['hello', 'world'])

        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', 1)
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', 'foo')
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', [1, 2])
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv', ['foo', 1])

        self.assertEqual(self.get_prop(self.obj, 'some-strv'), ['hello', 'world'])

        obj = GIMarshallingTests.PropertiesObject(some_strv=['hello', 'world'])
        self.assertEqual(self.get_prop(obj, 'some-strv'), ['hello', 'world'])

        # unicode on py2
        obj = GIMarshallingTests.PropertiesObject(some_strv=[_unicode('foo')])
        self.assertEqual(self.get_prop(obj, 'some-strv'), [_unicode('foo')])
        self.assertRaises(TypeError, self.set_prop, self.obj, 'some-strv',
                          [_unicode('foo'), 1])
Exemple #16
0
    def test_markup_escape_text(self):
        self.assertEqual(GLib.markup_escape_text(_unicode("a&bä")), "a&bä")
        self.assertEqual(GLib.markup_escape_text(_bytes("a&b\x05")), "a&b")

        # with explicit length argument
        self.assertEqual(GLib.markup_escape_text(_bytes("a\x05\x01\x02"), 2), "a")
Exemple #17
0
    def test_markup_escape_text(self):
        self.assertEqual(GLib.markup_escape_text(_unicode('a&bä')), 'a&bä')
        self.assertEqual(GLib.markup_escape_text(_bytes('a&b\x05')), 'a&b')

        # with explicit length argument
        self.assertEqual(GLib.markup_escape_text(_bytes('a\x05\x01\x02'), 2), 'a')