-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_integration.py
95 lines (76 loc) · 2.52 KB
/
test_integration.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import doctest
import subprocess
import functools
from unittest import TestCase
from cr8.run_crate import CrateNode, get_crate
from crate.client import connect
crate_dir = get_crate('latest-testing')
node = CrateNode(
crate_dir=crate_dir,
settings={
'cluster.name': 'cr8-tests',
'http.port': '44200-44250'
})
def setup(*args):
with connect(node.http_url) as conn:
c = conn.cursor()
c.execute('create table x.demo (id int, name string, country string) \
with (number_of_replicas = 0)')
c.execute('create table y.demo (name text) with (number_of_replicas = 0)')
c.execute('create blob table blobtable with (number_of_replicas = 0)')
def teardown(*args):
try:
with connect(node.http_url) as conn:
c = conn.cursor()
c.execute('drop table x.demo')
c.execute('drop blob table blobtable')
finally:
node.stop()
def transform(s):
s = s.replace('localhost:4200', node.http_url)
s = s.replace(
'asyncpg://localhost:5432',
f'asyncpg://{node.addresses.psql.host}:{node.addresses.psql.port}')
s = s.replace(
'postgresql://crate@localhost:5432/doc',
f'postgresql://crate@{node.addresses.psql.host}:{node.addresses.psql.port}/doc')
return (
r'print(sh("""%s""").stdout.decode("utf-8"))' % s) + '\n'
class Parser(doctest.DocTestParser):
def parse(self, string, name='<string>'):
r = super().parse(string, name)
for s in r:
if isinstance(s, doctest.Example):
s.source = transform(s.source)
return r
class SourceBuildTest(TestCase):
def test_build_from_branch(self):
self.assertIsNotNone(get_crate('4.1'))
def load_tests(loader, tests, ignore):
env = os.environ.copy()
env['CR8_NO_TQDM'] = 'True'
node.start()
assert node.http_host, "http_url must be available"
tests.addTests(doctest.DocFileSuite(
os.path.join('..', 'README.rst'),
globs={
'sh': functools.partial(
subprocess.run,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
timeout=60,
shell=True,
env=env
)
},
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS,
setUp=setup,
tearDown=teardown,
parser=Parser()
))
return tests
if __name__ == "__main__":
import unittest
unittest.main()