Added a seed option to the obi test command for reproducible tests
This commit is contained in:
@ -2,13 +2,9 @@ from obitools3.apps.progress cimport ProgressBar # TODO I absolutely don't unde
|
|||||||
from obitools3.obidms._obidms import OBIDMS # TODO cimport doesn't work
|
from obitools3.obidms._obidms import OBIDMS # TODO cimport doesn't work
|
||||||
from obitools3.utils cimport str2bytes
|
from obitools3.utils cimport str2bytes
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import shutil
|
import shutil
|
||||||
import unittest
|
|
||||||
import random
|
|
||||||
import string
|
import string
|
||||||
import psutil
|
import random
|
||||||
|
|
||||||
|
|
||||||
VIEW_TYPES = [None, "NUC_SEQS_VIEW"]
|
VIEW_TYPES = [None, "NUC_SEQS_VIEW"]
|
||||||
@ -65,7 +61,7 @@ def random_str_with_max_len(max_len):
|
|||||||
|
|
||||||
|
|
||||||
def random_column(infos):
|
def random_column(infos):
|
||||||
return random.choice(list(infos['view'].columns))
|
return random.choice(sorted(list(infos['view'].columns)))
|
||||||
|
|
||||||
|
|
||||||
def random_unique_name(infos):
|
def random_unique_name(infos):
|
||||||
@ -117,7 +113,7 @@ def test_add_col(config, infos):
|
|||||||
#existing_col = random_bool(config) # TODO doesn't work because of line count problem. See obiview.c line 1737
|
#existing_col = random_bool(config) # TODO doesn't work because of line count problem. See obiview.c line 1737
|
||||||
#if existing_col and infos["view_names"] != [] :
|
#if existing_col and infos["view_names"] != [] :
|
||||||
# random_view = infos['dms'].open_view(random.choice(infos["view_names"]))
|
# random_view = infos['dms'].open_view(random.choice(infos["view_names"]))
|
||||||
# random_column = random_view[random.choice(list(random_view.columns)]
|
# random_column = random_view[random.choice(sorted(list(random_view.columns))]
|
||||||
# random_column_refs = random_column.refs
|
# random_column_refs = random_column.refs
|
||||||
# if random_column_refs['name'] in infos['view'] :
|
# if random_column_refs['name'] in infos['view'] :
|
||||||
# alias = random_unique_name(infos)
|
# alias = random_unique_name(infos)
|
||||||
@ -230,7 +226,7 @@ def random_new_view(config, infos, first=False):
|
|||||||
line_selection = []
|
line_selection = []
|
||||||
for i in range(random.randint(1, v_to_clone.line_count)) :
|
for i in range(random.randint(1, v_to_clone.line_count)) :
|
||||||
line_selection.append(random.randint(0, v_to_clone.line_count-1))
|
line_selection.append(random.randint(0, v_to_clone.line_count-1))
|
||||||
print_test(config, "New line selection: "+str(line_selection))
|
#print_test(config, "New line selection: "+str(line_selection))
|
||||||
else :
|
else :
|
||||||
v_type = random_view_type()
|
v_type = random_view_type()
|
||||||
infos['view'] = infos['dms'].new_view(random_unique_name(infos),
|
infos['view'] = infos['dms'].new_view(random_unique_name(infos),
|
||||||
@ -337,8 +333,18 @@ def addOptions(parser):
|
|||||||
help="Print the tests. "
|
help="Print the tests. "
|
||||||
"Default: Don't print the tests")
|
"Default: Don't print the tests")
|
||||||
|
|
||||||
|
group.add_argument('--seed','-g',
|
||||||
|
action="store", dest="test:seed",
|
||||||
|
metavar='<SEED>',
|
||||||
|
default=None,
|
||||||
|
help="Seed (use for reproducible tests). "
|
||||||
|
"Default: Seed is determined by Python")
|
||||||
|
|
||||||
def run(config):
|
def run(config):
|
||||||
|
|
||||||
|
if 'seed' in config['test'] :
|
||||||
|
random.seed(config['test']['seed'])
|
||||||
|
|
||||||
infos = {'dms': None,
|
infos = {'dms': None,
|
||||||
'view': None,
|
'view': None,
|
||||||
'view_names': None,
|
'view_names': None,
|
||||||
@ -352,6 +358,7 @@ def run(config):
|
|||||||
print("Initializing the DMS and the first view...")
|
print("Initializing the DMS and the first view...")
|
||||||
|
|
||||||
ini_dms_and_first_view(config, infos)
|
ini_dms_and_first_view(config, infos)
|
||||||
|
print_test(config, repr(infos['view']))
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for t in range(config['test']['nbtests']):
|
for t in range(config['test']['nbtests']):
|
||||||
|
Reference in New Issue
Block a user