File: test_gopher_exceptions.py

package info (click to toggle)
pygopherd 3.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,928 kB
  • sloc: python: 6,534; makefile: 40; sh: 28
file content (40 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python

import unittest
from io import BytesIO

from pygopherd import GopherExceptions, testutil
from pygopherd.GopherExceptions import FileNotFound


class GopherExceptionsTestCase(unittest.TestCase):
    def setUp(self):
        self.config = testutil.get_config()
        self.stringfile = testutil.get_string_logger()
        GopherExceptions.tracebacks = 0

    def testlog_basic(self):
        try:
            raise IOError("foo")
        except IOError as e:
            GopherExceptions.log(e)
        self.assertEqual(
            self.stringfile.getvalue(),
            "unknown-address [None/None] EXCEPTION OSError: foo\n",
        )

    def testlog_proto_ip(self):
        rfile = BytesIO(b"/NONEXISTANT\n")
        wfile = BytesIO()
        handler = testutil.get_testing_handler(rfile, wfile, self.config)
        handler.handle()
        self.assertEqual(
            self.stringfile.getvalue(),
            "10.77.77.77 [GopherProtocol/None] EXCEPTION FileNotFound: '/NONEXISTANT' does not exist (no handler found)\n",
        )

    def testFileNotFound(self):
        try:
            raise FileNotFound("TEST STRING")
        except FileNotFound as e:
            self.assertEqual(str(e), "'TEST STRING' does not exist")