Debian Codegraph @

test/test_litmus.py

raw symbols SCIP
1 import re
2 import os
3 import sys
4 import time
5 import shutil
6 import tarfile
7 import tempfile
8 import unittest
9 import subprocess
10 from subprocess import run
11
12 testdir = os.path.abspath(os.path.dirname(__file__))
13 sys.path.insert(0, os.path.join(testdir, '..'))
14
15 import pywebdav.server.server
16
17 # Run davserver
18 user = 'test'
19 password = 'pass'
20 port = 38028
21
22 class TestFilter:
23 _suites = ['props']
24 _skipping = True
25
26 def skipLine(self, line):
27 if line.startswith("<- summary"):
28 self._skipping = False
29 else:
30 for suite in self._suites:
31 if line.startswith(f"-> running `{suite}"):
32 self._skipping = True
33 break
34 return self._skipping
35
36 class Test(unittest.TestCase):
37 def setUp(self):
38
39 self.rundir = tempfile.mkdtemp()
40 self._ensure_litmus()
41
42 def _ensure_litmus(self):
43
44 self.litmus_dist = os.path.join(testdir, 'litmus-0.13')
45 self.litmus = os.path.join(self.litmus_dist, 'litmus')
46 if not os.path.exists(self.litmus):
47 print('Compiling litmus test suite')
48
49 if os.path.exists(self.litmus_dist):
50 shutil.rmtree(self.litmus_dist)
51 with tarfile.open(self.litmus_dist + '.tar.gz') as tf:
52 tf.extractall(path=testdir)
53 ret = run(['sh', './configure'], cwd=self.litmus_dist)
54 # assert ret == 0
55 ret = run(['make'], cwd=self.litmus_dist)
56 # assert ret == 0
57 litmus = os.path.join(self.litmus_dist, 'litmus')
58 # assert os.path.exists(litmus)
59
60 def tearDown(self):
61 print("Cleaning up tempdir")
62 shutil.rmtree(self.rundir)
63
64 def test_run_litmus(self):
65
66 result = []
67 proc = None
68 try:
69 print('Starting davserver')
70 davserver_cmd = [sys.executable, os.path.join(testdir, '..', 'pywebdav', 'server', 'server.py'), '-D',
71 self.rundir, '-u', user, '-p', password, '-H', 'localhost', '--port', str(port)]
72 self.davserver_proc = subprocess.Popen(davserver_cmd)
73 # Ensure davserver has time to startup
74 time.sleep(1)
75
76 # Run Litmus
77 print('Running litmus')
78 try:
79 ret = run(["make", "URL=http://localhost:%d" % port, 'CREDS=%s %s' % (user, password), "check"], cwd=self.litmus_dist, capture_output=True)
80 results = ret.stdout
81 except subprocess.CalledProcessError as ex:
82 results = ex.output
83 lines = results.decode().split('\n')
84 assert len(lines), "No litmus output"
85 filter = TestFilter()
86 for line in lines:
87 line = line.split('\r')[-1]
88 result.append(line)
89 if filter.skipLine(line):
90 continue
91 if len(re.findall(r'^ *\d+\.', line)):
92 assert line.endswith('pass'), line
93
94 finally:
95 print('\n'.join(result))
96
97 print('Stopping davserver')
98 self.davserver_proc.kill()
99
100
101 def test_run_litmus_noauth(self):
102
103 result = []
104 proc = None
105 try:
106 print('Starting davserver')
107 davserver_cmd = [sys.executable, os.path.join(testdir, '..', 'pywebdav', 'server', 'server.py'), '-D',
108 self.rundir, '-n', '-H', 'localhost', '--port', str(port)]
109 self.davserver_proc = subprocess.Popen(davserver_cmd)
110 # Ensure davserver has time to startup
111 time.sleep(1)
112
113 # Run Litmus
114 print('Running litmus')
115 try:
116 ret = run(["make", "URL=http://localhost:%d" % port, "check"], cwd=self.litmus_dist, capture_output=True)
117 results = ret.stdout
118
119 except subprocess.CalledProcessError as ex:
120 results = ex.output
121 lines = results.decode().split('\n')
122 assert len(lines), "No litmus output"
123 filter = TestFilter()
124 for line in lines:
125 line = line.split('\r')[-1]
126 result.append(line)
127 if filter.skipLine(line):
128 continue
129 if len(re.findall(r'^ *\d+\.', line)):
130 assert line.endswith('pass'), line
131
132 finally:
133 print('\n'.join(result))
134
135 print('Stopping davserver')
136 self.davserver_proc.kill()
137
138 if __name__ == "__main__":
139 unittest.main()
140