From 9e700ddc212885e95e81911e9368f25296a69a8d Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Sun, 7 Oct 2018 19:10:46 +0200 Subject: [PATCH] obi test: updated to test comments --- python/obitools3/commands/test.pyx | 35 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/python/obitools3/commands/test.pyx b/python/obitools3/commands/test.pyx index cdd1363..80f1d2a 100644 --- a/python/obitools3/commands/test.pyx +++ b/python/obitools3/commands/test.pyx @@ -146,6 +146,18 @@ def random_str_with_max_len(max_len): def random_bytes_with_max_len(max_len): return str2bytes(random_str_with_max_len(max_len)) + +RANDOM_FUNCTIONS = [random_bool, random_char, random_bytes, random_float, random_int] +def random_comments(config): + comments = {} + for i in range(random_length(1000)): + to_add = {random_bytes(config): random.choice(RANDOM_FUNCTIONS)(config)} + if len(str(comments)) + len(str(to_add)) >= COL_COMMENTS_MAX_LEN: + return comments + else: + comments.update(to_add) + return comments + def random_column(infos): return random.choice(sorted(list(infos['view'].keys()))) @@ -305,7 +317,7 @@ def create_random_column(config, infos) : nb_elements_per_line=nb_elements_per_line, elements_names=elements_names, tuples=tuples, - comments=random_str_with_max_len(COL_COMMENTS_MAX_LEN), + comments=random_comments(config), alias=alias ) @@ -345,15 +357,15 @@ def random_new_view(config, infos, first=False): v_type = random_view_type() if line_selection is not None : - infos['view'] = line_selection.materialize(random_unique_name(infos), comments=random_bytes_with_max_len(config['test']['commentsmaxlen'])) + infos['view'] = line_selection.materialize(random_unique_name(infos), comments=random_comments(config)) elif v_to_clone is not None : - infos['view'] = v_to_clone.clone(random_unique_name(infos), comments=random_bytes_with_max_len(config['test']['commentsmaxlen'])) + infos['view'] = v_to_clone.clone(random_unique_name(infos), comments=random_comments(config)) else : if v_type == "NUC_SEQS_VIEW" : - infos['view'] = View_NUC_SEQS.new(infos['dms'], random_unique_name(infos), comments=random_bytes_with_max_len(config['test']['commentsmaxlen'])) # TODO quality column + infos['view'] = View_NUC_SEQS.new(infos['dms'], random_unique_name(infos), comments=random_comments(config)) # TODO quality column else : - infos['view'] = View.new(infos['dms'], random_unique_name(infos), comments=random_bytes_with_max_len(config['test']['commentsmaxlen'])) # TODO quality column - + infos['view'] = View.new(infos['dms'], random_unique_name(infos), comments=random_comments(config)) # TODO quality column + print_test(config, repr(infos['view'])) if v_to_clone is not None : if line_selection is None: @@ -429,15 +441,7 @@ def addOptions(parser): type=int, help="Maximum length of tuples. " "Default: 200") - - group.add_argument('--comments_max_len','-c', - action="store", dest="test:commentsmaxlen", - metavar='', - default=10000, - type=int, - help="Maximum length of view comments. " - "Default: 10000") - + group.add_argument('--max_ini_col_count','-o', action="store", dest="test:maxinicolcount", metavar='', @@ -495,6 +499,7 @@ def run(config): 'tests': [test_set_and_get, test_add_col, test_delete_col, test_col_alias, test_new_view] } + # TODO ??? config['test']['elt_name_max_len'] = int((COL_COMMENTS_MAX_LEN - config['test']['maxelts']) / config['test']['maxelts']) print("Initializing the DMS and the first view...")