55import sys
66import unittest
77
8- from cr8 .run_crate import CrateNode , get_crate
9- from cr8 .clients import client
10- from cr8 import aio
8+ from cr8 .run_crate import get_crate
9+ from tests .integration_util import teardown , node , setup , transform
1110
1211
13- crate_dir = get_crate ('latest-testing' )
14- node = CrateNode (
15- crate_dir = crate_dir ,
16- settings = {
17- 'cluster.name' : 'cr8-tests' ,
18- 'http.port' : '44200-44250'
19- })
20-
21-
22- def setup (* args ):
23- with client (node .http_url ) as c :
24- aio .run (
25- c .execute ,
26- 'create table x.demo (id int, name string, country string) \
27- with (number_of_replicas = 0)'
28- )
29- aio .run (c .execute , 'create table y.demo (name text) with (number_of_replicas = 0)' )
30- aio .run (c .execute , 'create blob table blobtable with (number_of_replicas = 0)' )
31-
32-
33- def teardown (* args ):
12+ def final_teardown (* args ):
3413 try :
35- with client (node .http_url ) as c :
36- aio .run (c .execute , 'drop table x.demo' )
37- aio .run (c .execute , 'drop blob table blobtable' )
14+ teardown ()
3815 finally :
3916 node .stop ()
4017
4118
42- def transform (s ):
43- s = s .replace ('localhost:4200' , node .http_url )
44- s = s .replace (
45- 'asyncpg://localhost:5432' ,
46- f'asyncpg://{ node .addresses .psql .host } :{ node .addresses .psql .port } ' )
47- s = s .replace (
48- 'postgresql://crate@localhost:5432/doc' ,
49- f'postgresql://crate@{ node .addresses .psql .host } :{ node .addresses .psql .port } /doc' )
50- return (
51- r'print(sh("""%s""").stdout.decode("utf-8"))' % s ) + '\n '
52-
53-
5419class Parser (doctest .DocTestParser ):
5520
5621 def parse (self , string , name = '<string>' ):
@@ -69,10 +34,23 @@ def test_build_from_branch(self):
6934
7035
7136def load_tests (loader , tests , ignore ):
37+ """
38+ Intercept test discovery, in order to add doctests from `README.rst`.
39+ """
40+
41+ # FIXME: doctests have errors on Windows.
42+ if sys .platform .startswith ("win" ):
43+ return tests
44+
45+ # Parsing doctests happens early, way before the test suite is invoked.
46+ # However, the doctest translator needs to know about the TCP address
47+ # of CrateDB, so it needs to be started right away.
7248 env = os .environ .copy ()
7349 env ['CR8_NO_TQDM' ] = 'True'
7450 node .start ()
7551 assert node .http_host , "http_url must be available"
52+
53+ # Add integration tests defined as doctests in README.rst.
7654 tests .addTests (doctest .DocFileSuite (
7755 os .path .join ('..' , 'README.rst' ),
7856 globs = {
@@ -88,7 +66,7 @@ def load_tests(loader, tests, ignore):
8866 },
8967 optionflags = doctest .NORMALIZE_WHITESPACE | doctest .ELLIPSIS ,
9068 setUp = setup ,
91- tearDown = teardown ,
69+ tearDown = final_teardown ,
9270 parser = Parser ()
9371 ))
9472 return tests
0 commit comments