Added a seed option to the obi test command for reproducible tests

This commit is contained in:
Celine Mercier
2016-09-29 17:34:48 +02:00
parent 8c402101e4
commit d88811ed7d

View File

@ -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.utils cimport str2bytes
import os
import sys
import shutil
import unittest
import random
import string
import psutil
import random
VIEW_TYPES = [None, "NUC_SEQS_VIEW"]
@ -65,7 +61,7 @@ def random_str_with_max_len(max_len):
def random_column(infos):
return random.choice(list(infos['view'].columns))
return random.choice(sorted(list(infos['view'].columns)))
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
#if existing_col and 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
# if random_column_refs['name'] in infos['view'] :
# alias = random_unique_name(infos)
@ -230,7 +226,7 @@ def random_new_view(config, infos, first=False):
line_selection = []
for i in range(random.randint(1, v_to_clone.line_count)) :
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 :
v_type = random_view_type()
infos['view'] = infos['dms'].new_view(random_unique_name(infos),
@ -288,7 +284,7 @@ def addOptions(parser):
metavar='<SEQ_MAX_LEN>',
default=200,
type=int,
help="Maximum length of DNA sequences."
help="Maximum length of DNA sequences. "
"Default: 200")
group.add_argument('--str_max_len','-t',
@ -296,7 +292,7 @@ def addOptions(parser):
metavar='<STR_MAX_LEN>',
default=200,
type=int,
help="Maximum length of character strings."
help="Maximum length of character strings. "
"Default: 200")
group.add_argument('--comments_max_len','-c',
@ -304,7 +300,7 @@ def addOptions(parser):
metavar='<COMMENTS_MAX_LEN>',
default=10000,
type=int,
help="Maximum length of view comments."
help="Maximum length of view comments. "
"Default: 10000")
group.add_argument('--max_ini_col_count','-o',
@ -312,7 +308,7 @@ def addOptions(parser):
metavar='<MAX_INI_COL_COUNT>',
default=10,
type=int,
help="Maximum number of columns in the initial view."
help="Maximum number of columns in the initial view. "
"Default: 10")
group.add_argument('--max_line_nb','-l',
@ -320,7 +316,7 @@ def addOptions(parser):
metavar='<MAX_LINE_NB>',
default=10000,
type=int,
help="Maximum number of lines in a column."
help="Maximum number of lines in a column. "
"Default: 10000")
group.add_argument('--max_elts_per_line','-e',
@ -328,17 +324,27 @@ def addOptions(parser):
metavar='<MAX_ELTS_PER_LINE>',
default=20,
type=int,
help="Maximum number of elements per line in a column."
help="Maximum number of elements per line in a column. "
"Default: 20")
group.add_argument('--verbose','-v',
action="store_true", dest="test:verbose",
default=False,
help="Print the tests."
help="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):
if 'seed' in config['test'] :
random.seed(config['test']['seed'])
infos = {'dms': None,
'view': None,
'view_names': None,
@ -352,6 +358,7 @@ def run(config):
print("Initializing the DMS and the first view...")
ini_dms_and_first_view(config, infos)
print_test(config, repr(infos['view']))
i = 0
for t in range(config['test']['nbtests']):