summaryrefslogtreecommitdiffstats
path: root/tests/QtCore/bug_723.py
blob: 68ebeab618b71552fb2706ef82d11a3f4cf7caa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import unittest
from PySide.QtCore import *

class MyFileEngine (QAbstractFileEngine):

    def __init__(self):
        QAbstractFileEngine.__init__(self)
        self.contents = "Foo bar for the win!"
        self.pos = 0

    def open(self, mode):
        return True

    def read(self, maxlen):
        print "Reading... to return ", self.contents[self.pos:maxlen]

        if self.pos > len(self.contents):
            return -1

        res = self.contents[self.pos:maxlen]
        self.pos += len(res)
        return res

    def readLine(self, maxlen):
        return self.contents[self.pos:maxlen]

class MyFileEngineHandler (QAbstractFileEngineHandler):

    def create(self, fileName):
        print "hey ho: ", fileName
        if fileName.startswith("foo:/"):
            return MyFileEngine()
        return None


class TestBug723 (unittest.TestCase):

    def testIt(self):
        fh = MyFileEngineHandler()

        f = QFile("foo:/bar")

        assert(f.open(QFile.ReadOnly | QFile.Text))
        contents = f.readAll()
        self.assertEqual(contents, "Foo bar for the win!")
        f.close()


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