forked from pauldmccarthy/indexed_gzip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
96 lines (67 loc) · 2.26 KB
/
conftest.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
96
#!/usr/bin/env python
#
# conftest.py -
#
# Author: Paul McCarthy <[email protected]>
#
import os
import os.path as op
import numpy as np
import pytest
from indexed_gzip.tests import gen_test_data
def pytest_addoption(parser):
parser.addoption('--nelems',
type=int,
action='store',
default=2**24 + 1,
help='Number of uint64 elements for test data')
parser.addoption('--concat',
action='store_true',
help='Generate test data made of '
'concatenated GZIP streams')
parser.addoption('--use_mmap',
action='store_true',
help='Use mmap for read buffer instead of main memory')
parser.addoption('--seed',
type=int,
help='Seed for random number generator')
parser.addoption('--testfile',
action='store',
help='Name of test file')
parser.addoption('--niters',
type=int,
action='store',
default=5000,
help='Number of inputs for tests which '
'use a random set of inputs')
@pytest.fixture
def nelems(request):
return request.config.getoption('--nelems')
@pytest.fixture
def niters(request):
return request.config.getoption('--niters')
@pytest.fixture
def concat(request):
return request.config.getoption('--concat')
@pytest.fixture
def use_mmap(request):
return request.config.getoption('--use_mmap')
@pytest.fixture
def seed(request):
seed = request.config.getoption('--seed')
if seed is None:
seed = np.random.randint(2 ** 30)
np.random.seed(seed)
print('Seed for random number generator: {}'.format(seed))
return seed
@pytest.fixture
def testfile(request):
filename = request.config.getoption('--testfile')
_nelems = nelems(request)
_concat = concat(request)
if filename is None:
filename = op.join(os.getcwd(),
'ctest_zran_{}_{}.gz'.format(_nelems, _concat))
if not op.exists(filename):
gen_test_data(filename, _nelems, _concat)
return filename