annotate tests/__init__.py @ 72:e8b3b336e63e draft default tip

Update version.
author David Barts <n5jrn@me.com>
date Mon, 15 Jul 2019 13:17:48 -0700
parents 88adf10be709
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
71
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 #!/usr/bin/env python3
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
2
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 # I m p o r t s
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
4
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
5 import unittest
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 import tincan
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import logging
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import subprocess
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import time
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
10
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 # V a r i a b l e s
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
12
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 LOGGERNAME = "run-tests-server"
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 LOGNAME = "run-tests-server.log"
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
15
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 # F u n c t i o n s
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
17
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 def _flush(logger):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 for handler in logger.handlers:
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 handler.flush()
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
21
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 # C l a s s e s
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
23
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 class ServerFixture(unittest.TestCase):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
25 """
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 This tests if we can launch something successfully or not. It is intended
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 to have but a single test case, which checks that cls.errors is 0.
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
28 """
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 files = None
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 port = None
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 app = None
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 errors = None
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
33
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 @classmethod
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 def setUpClass(cls):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
36 mylog = logging.getLogger(LOGGERNAME)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
37 mylog.info("*** BEGIN %s.%s", cls.__module__, cls.__name__)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
38 cls.app, cls.errors = tincan.launch(fsroot=cls.files, logger=mylog)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
39 mylog.info("*** END %s.%s", cls.__module__, cls.__name__)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
40
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
41 @classmethod
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
42 def tearDownClass(cls):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
43 pass
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
44
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 class RoutesFixture(unittest.TestCase):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 """
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 This is for testing routes. It assumes the server will start and run,
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
48 and runs that server in a separate process. It can (and often will) have
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
49 multiple test cases, which will use requests and html.parser to verify
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 the output is as expected.
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 """
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
52 files = None
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
53 port = None
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 server = None
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 logger = None
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
56
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
57 @classmethod
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 def setUpClass(cls):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
59 mylog = logging.getLogger(LOGGERNAME)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
60 mylog.info("*** BEGIN %s.%s", cls.__module__, cls.__name__)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
61 _flush(mylog)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
62 cls.logger = open(LOGNAME, "a")
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
63 cls.server = subprocess.Popen(
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 [ "bin/launch", "--port={0}".format(cls.port), cls.files, ],
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
65 stdin=subprocess.DEVNULL, stdout=cls.logger, stderr=cls.logger)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 time.sleep(3) # xxx
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
67
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 @classmethod
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
69 def tearDownClass(cls):
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
70 cls.server.terminate()
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
71 cls.server.wait()
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 cls.logger.close()
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 mylog = logging.getLogger(LOGGERNAME)
88adf10be709 Add tests.
David Barts <n5jrn@me.com>
parents:
diff changeset
74 mylog.info("*** END %s.%s", cls.__module__, cls.__name__)