From c9e5ea428684590ab11fa2cadbd2a60b72f98168 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 16 Jul 2020 16:20:27 +0300 Subject: Expose elastic-search variables for tests to pass --- wqflask/utility/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 89d88516..77db5d53 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -270,8 +270,8 @@ if ORCID_CLIENT_ID != 'UNKNOWN' and ORCID_CLIENT_SECRET: ORCID_CLIENT_ID+"&client_secret="+ORCID_CLIENT_SECRET ORCID_TOKEN_URL = get_setting('ORCID_TOKEN_URL') -# ELASTICSEARCH_HOST = get_setting('ELASTICSEARCH_HOST') -# ELASTICSEARCH_PORT = get_setting('ELASTICSEARCH_PORT') +ELASTICSEARCH_HOST = get_setting('ELASTICSEARCH_HOST') +ELASTICSEARCH_PORT = get_setting('ELASTICSEARCH_PORT') # import utility.elasticsearch_tools as es # es.test_elasticsearch_connection() -- cgit v1.2.3 From f4e61929d0eb490dbf7e8ddc03a20d42d44b6f5c Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 21 Jul 2020 12:36:06 +0300 Subject: Add work-around for failed imports in unittest * wqflask/utility/tools.py: Unittests will use `from wqflask.wqflask import app` and the gn2 script will use `from wqflask import app` --- wqflask/utility/tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 77db5d53..37f9d8fe 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -5,7 +5,10 @@ import os import sys import json -from wqflask import app +try: + from wqflask import app +except ImportError: + from wqflask.wqflask import app # Use the standard logger here to avoid a circular dependency import logging -- cgit v1.2.3 From 2cbda12fe9fa9fca4d27796b2a8eb719e659dc7f Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 21 Jul 2020 21:53:30 +0300 Subject: Revert "Add work-around for failed imports in unittest" This reverts commit d5e87fa6fe7546b46790f512d984a5501223082f. --- wqflask/utility/tools.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 37f9d8fe..77db5d53 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -5,10 +5,7 @@ import os import sys import json -try: - from wqflask import app -except ImportError: - from wqflask.wqflask import app +from wqflask import app # Use the standard logger here to avoid a circular dependency import logging -- cgit v1.2.3 From d26ca838b6e823303c4b903c286fcc452caed0ad Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 21 Jul 2020 23:37:21 +0300 Subject: Remove unused doc-tests * wqflask/utility/chunks.py: Remove test code from module --- wqflask/utility/chunks.py | 63 ----------------------------------------------- 1 file changed, 63 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/chunks.py b/wqflask/utility/chunks.py index b0e33c08..d91b9bf4 100644 --- a/wqflask/utility/chunks.py +++ b/wqflask/utility/chunks.py @@ -31,66 +31,3 @@ def divide_into_chunks(the_list, number_chunks): chunks.append(the_list[counter:counter+chunksize]) return chunks - -def _confirm_chunk(original, result): - all_chunked = [] - for chunk in result: - all_chunked.extend(chunk) - print("length of all chunked:", len(all_chunked)) - assert original == all_chunked, "You didn't chunk right" - - -def _chunk_test(divide_func): - import random - random.seed(7) - - number_exact = 0 - total_amount_off = 0 - - for test in range(1, 1001): - print("\n\ntest:", test) - number_chunks = random.randint(1, 20) - number_elements = random.randint(0, 100) - the_list = list(range(1, number_elements)) - result = divide_func(the_list, number_chunks) - - print("Dividing list of length {} into approximately {} chunks - got {} chunks".format( - len(the_list), number_chunks, len(result))) - print("result:", result) - - _confirm_chunk(the_list, result) - - amount_off = abs(number_chunks - len(result)) - if amount_off == 0: - number_exact += 1 - else: - total_amount_off += amount_off - - - print("\n{} exact out of {} [Total amount off: {}]".format(number_exact, - test, - total_amount_off)) - assert number_exact == 558 - assert total_amount_off == 1580 - return number_exact, total_amount_off - - -def _main(): - info = dict() - #funcs = (("sam", sam_divide_into_chunks), ("zach", zach_divide_into_chunks)) - funcs = (("only one", divide_into_chunks),) - for name, func in funcs: - start = time.time() - number_exact, total_amount_off = _chunk_test(func) - took = time.time() - start - info[name] = dict(number_exact=number_exact, - total_amount_off=total_amount_off, - took=took) - - print("info is:", info) - -if __name__ == '__main__': - _main() - print("\nConfirming doctests...") - import doctest - doctest.testmod() -- cgit v1.2.3 From b39ef1e464208cf8806dc73cfe9684183ce7c9a2 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 22 Jul 2020 01:37:52 +0300 Subject: Simplify normalize_values * wqflask/utility/corr_result_helpers.py(normalize_values): Replace loop with zip form --- wqflask/utility/corr_result_helpers.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/corr_result_helpers.py b/wqflask/utility/corr_result_helpers.py index b543c589..69c6fe1b 100644 --- a/wqflask/utility/corr_result_helpers.py +++ b/wqflask/utility/corr_result_helpers.py @@ -14,15 +14,11 @@ def normalize_values(a_values, b_values): min_length = min(len(a_values), len(b_values)) a_new = [] b_new = [] - for counter in range(min_length): - if (a_values[counter] or a_values[counter] == 0) and (b_values[counter] or b_values[counter] == 0): - a_new.append(a_values[counter]) - b_new.append(b_values[counter]) - - num_overlap = len(a_new) - assert num_overlap == len(b_new), "Lengths should be the same" - - return a_new, b_new, num_overlap + for a, b in zip(a_values, b_values): + if not (a == None or b == None): + a_new.append(a) + b_new.append(b) + return a_new, b_new, len(a_new) def common_keys(a_samples, b_samples): -- cgit v1.2.3 From f99df1fa0f2163a93f7e194beeb65f0e1d542594 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 22 Jul 2020 01:40:03 +0300 Subject: Remove unused doc-tests * wqflask/utility/corr_result_helpers.py: Delete doc-test --- wqflask/utility/corr_result_helpers.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/corr_result_helpers.py b/wqflask/utility/corr_result_helpers.py index 69c6fe1b..09017e4a 100644 --- a/wqflask/utility/corr_result_helpers.py +++ b/wqflask/utility/corr_result_helpers.py @@ -44,9 +44,3 @@ def normalize_values_with_samples(a_samples, b_samples): assert num_overlap == len(b_new), "Lengths should be the same" return a_new, b_new, num_overlap - - - -if __name__ == '__main__': - import doctest - doctest.testmod() \ No newline at end of file -- cgit v1.2.3 From 2b7d50f9ac6d0f4f6a032e60053b5923c292a0a1 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 22 Jul 2020 01:41:14 +0300 Subject: Remove unused assert * wqflask/utility/corr_result_helpers.py(normalize_values): At no one point will that assert be hit --- wqflask/utility/corr_result_helpers.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/corr_result_helpers.py b/wqflask/utility/corr_result_helpers.py index 09017e4a..a43edbd4 100644 --- a/wqflask/utility/corr_result_helpers.py +++ b/wqflask/utility/corr_result_helpers.py @@ -33,14 +33,10 @@ def common_keys(a_samples, b_samples): def normalize_values_with_samples(a_samples, b_samples): common_samples = common_keys(a_samples, b_samples) - a_new = {} b_new = {} for sample in common_samples: a_new[sample] = a_samples[sample] b_new[sample] = b_samples[sample] - num_overlap = len(a_new) - assert num_overlap == len(b_new), "Lengths should be the same" - return a_new, b_new, num_overlap -- cgit v1.2.3 From 82ee315583281b93e1eff9640ce04e44bc70ac58 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 22 Jul 2020 01:41:45 +0300 Subject: Remove redundant variable * wqflask/utility/corr_result_helpers.py(normalize_values_with_values): Remove `num_overlap` --- wqflask/utility/corr_result_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/corr_result_helpers.py b/wqflask/utility/corr_result_helpers.py index a43edbd4..ea3ababf 100644 --- a/wqflask/utility/corr_result_helpers.py +++ b/wqflask/utility/corr_result_helpers.py @@ -39,4 +39,4 @@ def normalize_values_with_samples(a_samples, b_samples): a_new[sample] = a_samples[sample] b_new[sample] = b_samples[sample] - return a_new, b_new, num_overlap + return a_new, b_new, len(a_new) -- cgit v1.2.3 From aed1b7f12f653694c22ab389a403120e143a0669 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 22 Jul 2020 17:03:37 +0300 Subject: Add zero to num_repr dictionary * wqflask/utility/formatting.py(numify): Update `num_repr` to have a zero --- wqflask/utility/formatting.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/formatting.py b/wqflask/utility/formatting.py index e53dda22..1c0269e9 100644 --- a/wqflask/utility/formatting.py +++ b/wqflask/utility/formatting.py @@ -28,7 +28,8 @@ def numify(number, singular=None, plural=None): '12,334 hippopotami' """ - num_repr = {1 : "one", + num_repr = {0 : "zero", + 1 : "one", 2 : "two", 3 : "three", 4 : "four", -- cgit v1.2.3 From 073e8c9813505fc00372b2ec21f3e4a87b5be9aa Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 22 Jul 2020 17:05:11 +0300 Subject: Apply autopep-8 * wqflask/utility/formatting.py: apply it --- wqflask/utility/formatting.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/formatting.py b/wqflask/utility/formatting.py index 1c0269e9..1da3e9b7 100644 --- a/wqflask/utility/formatting.py +++ b/wqflask/utility/formatting.py @@ -28,22 +28,20 @@ def numify(number, singular=None, plural=None): '12,334 hippopotami' """ - num_repr = {0 : "zero", - 1 : "one", - 2 : "two", - 3 : "three", - 4 : "four", - 5 : "five", - 6 : "six", - 7 : "seven", - 8 : "eight", - 9 : "nine", - 10 : "ten", - 11 : "eleven", - 12 : "twelve"} - - #Below line commented out cause doesn't work in Python 2.4 - #assert all((singular, plural)) or not any((singular, plural)), "Need to pass two words or none" + num_repr = {0: "zero", + 1: "one", + 2: "two", + 3: "three", + 4: "four", + 5: "five", + 6: "six", + 7: "seven", + 8: "eight", + 9: "nine", + 10: "ten", + 11: "eleven", + 12: "twelve"} + if number == 1: word = singular else: -- cgit v1.2.3 From b8e17aee9000943e0fd379b5ef006d76314733e4 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 21 Jul 2020 12:36:06 +0300 Subject: Add work-around for failed imports in unittest * wqflask/utility/tools.py: Unittests will use `from wqflask.wqflask import app` and the gn2 script will use `from wqflask import app` --- wqflask/utility/tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 77db5d53..37f9d8fe 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -5,7 +5,10 @@ import os import sys import json -from wqflask import app +try: + from wqflask import app +except ImportError: + from wqflask.wqflask import app # Use the standard logger here to avoid a circular dependency import logging -- cgit v1.2.3 From 98035fccfd7960e6992e1e47afc32b56d54ff074 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 21 Jul 2020 21:53:30 +0300 Subject: Revert "Add work-around for failed imports in unittest" This reverts commit d5e87fa6fe7546b46790f512d984a5501223082f. --- wqflask/utility/tools.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'wqflask/utility') diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 37f9d8fe..77db5d53 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -5,10 +5,7 @@ import os import sys import json -try: - from wqflask import app -except ImportError: - from wqflask.wqflask import app +from wqflask import app # Use the standard logger here to avoid a circular dependency import logging -- cgit v1.2.3