Debian Codegraph @

x3270if/Test/Json.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 #
3 # Copyright (c) 2021-2022 Paul Mattes.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the names of Paul Mattes nor the names of his contributors
14 # may be used to endorse or promote products derived from this software
15 # without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY PAUL MATTES "AS IS" AND ANY EXPRESS OR IMPLIED
18 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 # EVENT SHALL PAUL MATTES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28 # x3270if JSON tests
29
30 import unittest
31 from subprocess import Popen, PIPE, DEVNULL
32 import json
33 import TestCommon
34
35 class TestX3270ifJson(unittest.TestCase):
36
37 # Set up procedure.
38 def setUp(self):
39 self.children = []
40
41 # Tear-down procedure.
42 def tearDown(self):
43 # Tidy up the children.
44 for child in self.children:
45 child.kill()
46 child.wait()
47
48 # x3270if basic JSON test
49 def test_x3270if_json(self):
50
51 # Start a copy of s3270 to talk to.
52 port, ts = TestCommon.unused_port()
53 s3270 = Popen(["s3270", "-scriptport", f"127.0.0.1:{port}"],
54 stdin=DEVNULL, stdout=DEVNULL)
55 self.children.append(s3270)
56 TestCommon.check_listen(port)
57 ts.close()
58
59 # Run x3270if with a trivial JSON query.
60 x3270if = Popen(["x3270if", "-t", str(port), '"Set(startTls)"'],
61 stdout=PIPE)
62 self.children.append(x3270if)
63
64 # Decode the result.
65 stdout = x3270if.communicate()[0].decode('utf8')
66
67 # Wait for the processes to exit.
68 s3270.kill()
69 s3270.wait()
70
71 # Test the output.
72 j = json.loads(stdout)
73 self.assertEqual('true', j['result'][0])
74 self.assertTrue(j['success'])
75 self.assertTrue(j['status'].startswith('L U U N N 4 24 80 0 0 0x0 '))
76
77 if __name__ == '__main__':
78 unittest.main()