コード例 #1
0
ファイル: test_misc.py プロジェクト: B-Rich/paytoopass
    def testSeekable(self):
        from ClientCookie._Util import seek_wrapper
        text = self.text
        text_lines = self.text_lines

        for ii in range(1, 6):
            fh = TestUnSeekable(text)
            sfh = seek_wrapper(fh)
            test = getattr(self, "_test%d" % ii)
            test(sfh)

        # copies have independent seek positions
        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        self._testCopy(sfh)
コード例 #2
0
ファイル: test_misc.py プロジェクト: FaNnT0m/paytoopass
    def testSeekable(self):
        from ClientCookie._Util import seek_wrapper
        text = self.text
        text_lines = self.text_lines

        for ii in range(1, 6):
            fh = TestUnSeekable(text)
            sfh = seek_wrapper(fh)
            test = getattr(self, "_test%d" % ii)
            test(sfh)

        # copies have independent seek positions
        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        self._testCopy(sfh)
コード例 #3
0
    def testSeekable(self):
        try:
            from exceptions import StopIteration
        except ImportError:
            from ClientCookie._ClientCookie import StopIteration
        from ClientCookie._Util import seek_wrapper
        text = """\
The quick brown fox
jumps over the lazy

dog.

"""
        text_lines = map(lambda l: l + "\n", string.split(text, "\n")[:-1])
        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        assert sfh.read(10) == text[:10]  # calls fh.read
        assert fh.log[-1] == ("read", 10)
        sfh.seek(0)  # doesn't call fh.seek
        assert sfh.read(10) == text[:10]  # doesn't call fh.read
        assert len(fh.log) == 1
        sfh.seek(0)
        assert sfh.read(5) == text[:5]  # read only part of cached data
        assert len(fh.log) == 1
        sfh.seek(0)
        assert sfh.read(25) == text[:25]  # calls fh.read
        assert fh.log[1] == ("read", 15)
        lines = []
        sfh.seek(-1, 1)
        while 1:
            l = sfh.readline()
            if l == "": break
            lines.append(l)
        assert lines == ["s over the lazy\n"] + text_lines[2:]
        assert fh.log[2:] == [("readline", -1)] * 5
        sfh.seek(0)
        lines = []
        while 1:
            l = sfh.readline()
            if l == "": break
            lines.append(l)
        assert lines == text_lines

        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        sfh.read(5)
        sfh.seek(0)
        assert sfh.read() == text
        assert sfh.read() == ""
        sfh.seek(0)
        assert sfh.read() == text
        sfh.seek(0)
        assert sfh.readline(5) == "The q"
        assert sfh.read() == text[5:]
        sfh.seek(0)
        assert sfh.readline(5) == "The q"
        assert sfh.readline() == "uick brown fox\n"

        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        sfh.read(25)
        sfh.seek(-1, 1)
        assert sfh.readlines() == ["s over the lazy\n"] + text_lines[2:]
        nr_logs = len(fh.log)
        sfh.seek(0)
        assert sfh.readlines() == text_lines

        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        count = 0
        limit = 10
        while count < limit:
            if count == 5:
                self.assertRaises(StopIteration, sfh.next)
                break
            else:
                sfh.next() == text_lines[count]
            count = count + 1
        else:
            assert False, "StopIteration not raised"
コード例 #4
0
ファイル: test_misc.py プロジェクト: raidenawkward/django
    def testSeekable(self):
        try:
            from exceptions import StopIteration
        except ImportError:
            from ClientCookie._ClientCookie import StopIteration
        from ClientCookie._Util import seek_wrapper
        text = """\
The quick brown fox
jumps over the lazy

dog.

"""
        text_lines = map(lambda l: l+"\n", string.split(text, "\n")[:-1])
        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        assert sfh.read(10) == text[:10]  # calls fh.read
        assert fh.log[-1] == ("read", 10)
        sfh.seek(0)  # doesn't call fh.seek
        assert sfh.read(10) == text[:10]  # doesn't call fh.read
        assert len(fh.log) == 1
        sfh.seek(0)
        assert sfh.read(5) == text[:5]  # read only part of cached data
        assert len(fh.log) == 1
        sfh.seek(0)
        assert sfh.read(25) == text[:25]  # calls fh.read
        assert fh.log[1] == ("read", 15)
        lines = []
        sfh.seek(-1, 1)
        while 1:
            l = sfh.readline()
            if l == "": break
            lines.append(l)
        assert lines == ["s over the lazy\n"]+text_lines[2:]
        assert fh.log[2:] == [("readline", -1)]*5
        sfh.seek(0)
        lines = []
        while 1:
            l = sfh.readline()
            if l == "": break
            lines.append(l)
        assert lines == text_lines

        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        sfh.read(5)
        sfh.seek(0)
        assert sfh.read() == text
        assert sfh.read() == ""
        sfh.seek(0)
        assert sfh.read() == text
        sfh.seek(0)
        assert sfh.readline(5) == "The q"
        assert sfh.read() == text[5:]
        sfh.seek(0)
        assert sfh.readline(5) == "The q"
        assert sfh.readline() == "uick brown fox\n"

        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        sfh.read(25)
        sfh.seek(-1, 1)
        assert sfh.readlines() == ["s over the lazy\n"]+text_lines[2:]
        nr_logs = len(fh.log)
        sfh.seek(0)
        assert sfh.readlines() == text_lines

        fh = TestUnSeekable(text)
        sfh = seek_wrapper(fh)
        count = 0
        limit = 10
        while count < limit:
            if count == 5:
                self.assertRaises(StopIteration, sfh.next)
                break
            else:
                sfh.next() == text_lines[count]
            count = count + 1
        else:
            assert False, "StopIteration not raised"