mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with function
parent
1fca4e909e
commit
831ea8a612
150
tests.py
150
tests.py
|
|
@ -246,6 +246,7 @@ from gemini import blog_to_gemini
|
||||||
from blog import html_blog_post_gemini_links
|
from blog import html_blog_post_gemini_links
|
||||||
from data import load_list
|
from data import load_list
|
||||||
from data import load_string
|
from data import load_string
|
||||||
|
from data import save_string
|
||||||
|
|
||||||
|
|
||||||
TEST_SERVER_GROUP_RUNNING = False
|
TEST_SERVER_GROUP_RUNNING = False
|
||||||
|
|
@ -2136,7 +2137,9 @@ def test_shared_items_federation(base_dir: str) -> None:
|
||||||
alice_domain, alice_port)
|
alice_domain, alice_port)
|
||||||
filename = bob_dir_str + '/bob@' + bob_domain + '/followers.txt'
|
filename = bob_dir_str + '/bob@' + bob_domain + '/followers.txt'
|
||||||
if not text_in_file('alice@' + alice_domain, filename):
|
if not text_in_file('alice@' + alice_domain, filename):
|
||||||
text = load_string(filename, '')
|
text: str = load_string(filename,
|
||||||
|
'EX: test_shared_items_federation load ' +
|
||||||
|
filename)
|
||||||
print('alice@' + alice_domain + ' not in\n' + str(text))
|
print('alice@' + alice_domain + ' not in\n' + str(text))
|
||||||
assert text_in_file('alice@' + alice_domain, filename)
|
assert text_in_file('alice@' + alice_domain, filename)
|
||||||
assert text_in_file('bob@' + bob_domain,
|
assert text_in_file('bob@' + bob_domain,
|
||||||
|
|
@ -2658,9 +2661,10 @@ def test_group_follow(base_dir: str) -> None:
|
||||||
print('acct: exists within the webfinger endpoint for testgroup')
|
print('acct: exists within the webfinger endpoint for testgroup')
|
||||||
|
|
||||||
testgroup_handle = 'testgroup@' + testgroup_domain
|
testgroup_handle = 'testgroup@' + testgroup_domain
|
||||||
following_str = ''
|
following_str: str = \
|
||||||
with open(alice_following_filename, 'r', encoding='utf-8') as fp_foll:
|
load_string(alice_following_filename,
|
||||||
following_str = fp_foll.read()
|
'EX: test_group_follow load 1 ' + alice_following_filename)
|
||||||
|
if following_str:
|
||||||
print('Alice following.txt:\n\n' + following_str)
|
print('Alice following.txt:\n\n' + following_str)
|
||||||
if '!testgroup' not in following_str:
|
if '!testgroup' not in following_str:
|
||||||
print('Alice following.txt does not contain !testgroup@' +
|
print('Alice following.txt does not contain !testgroup@' +
|
||||||
|
|
@ -2739,9 +2743,10 @@ def test_group_follow(base_dir: str) -> None:
|
||||||
print('acct: exists within the webfinger endpoint for testgroup')
|
print('acct: exists within the webfinger endpoint for testgroup')
|
||||||
|
|
||||||
testgroup_handle = 'testgroup@' + testgroup_domain
|
testgroup_handle = 'testgroup@' + testgroup_domain
|
||||||
following_str = ''
|
following_str: str = \
|
||||||
with open(bob_following_filename, 'r', encoding='utf-8') as fp_foll:
|
load_string(bob_following_filename,
|
||||||
following_str = fp_foll.read()
|
'EX: test_group_follow load 2 ' + bob_following_filename)
|
||||||
|
if following_str:
|
||||||
print('Bob following.txt:\n\n' + following_str)
|
print('Bob following.txt:\n\n' + following_str)
|
||||||
if '!testgroup' not in following_str:
|
if '!testgroup' not in following_str:
|
||||||
print('Bob following.txt does not contain !testgroup@' +
|
print('Bob following.txt does not contain !testgroup@' +
|
||||||
|
|
@ -3079,29 +3084,35 @@ def _test_follows(base_dir: str) -> None:
|
||||||
federation_list, False, False, 'following.txt')
|
federation_list, False, False, 'following.txt')
|
||||||
|
|
||||||
account_dir = acct_dir(base_dir, nickname, domain)
|
account_dir = acct_dir(base_dir, nickname, domain)
|
||||||
with open(account_dir + '/following.txt', 'r',
|
foll_list1: list[str] = \
|
||||||
encoding='utf-8') as fp_foll:
|
load_list(account_dir + '/following.txt',
|
||||||
domain_found: bool = False
|
'EX: _test_follows load list ' +
|
||||||
for following_domain in fp_foll:
|
account_dir + '/following.txt')
|
||||||
test_domain = following_domain.split('@')[1]
|
domain_found: bool = False
|
||||||
test_domain = remove_eol(test_domain)
|
for following_domain in foll_list1:
|
||||||
if test_domain == 'mesh.com':
|
test_domain = following_domain.split('@')[1]
|
||||||
domain_found = True
|
test_domain = remove_eol(test_domain)
|
||||||
if test_domain not in federation_list:
|
if test_domain == 'mesh.com':
|
||||||
print(test_domain)
|
domain_found = True
|
||||||
assert False
|
if test_domain not in federation_list:
|
||||||
|
print(test_domain)
|
||||||
|
assert False
|
||||||
|
assert domain_found
|
||||||
|
|
||||||
assert domain_found
|
unfollow_account(base_dir, nickname, domain, 'batman', 'mesh.com',
|
||||||
unfollow_account(base_dir, nickname, domain, 'batman', 'mesh.com',
|
True, False, 'following.txt')
|
||||||
True, False, 'following.txt')
|
|
||||||
|
|
||||||
domain_found: bool = False
|
foll_list2: list[str] = \
|
||||||
for following_domain in fp_foll:
|
load_list(account_dir + '/following.txt',
|
||||||
test_domain = following_domain.split('@')[1]
|
'EX: _test_follows load list ' +
|
||||||
test_domain = remove_eol(test_domain)
|
account_dir + '/following.txt')
|
||||||
if test_domain == 'mesh.com':
|
domain_found: bool = False
|
||||||
domain_found = True
|
for following_domain in foll_list2:
|
||||||
assert domain_found is False
|
test_domain = following_domain.split('@')[1]
|
||||||
|
test_domain = remove_eol(test_domain)
|
||||||
|
if test_domain == 'mesh.com':
|
||||||
|
domain_found = True
|
||||||
|
assert domain_found is False
|
||||||
|
|
||||||
clear_followers(base_dir, nickname, domain)
|
clear_followers(base_dir, nickname, domain)
|
||||||
add_follower_of_person(base_dir, nickname, domain, 'badger', 'wild.com',
|
add_follower_of_person(base_dir, nickname, domain, 'badger', 'wild.com',
|
||||||
|
|
@ -3118,14 +3129,16 @@ def _test_follows(base_dir: str) -> None:
|
||||||
federation_list, False, False)
|
federation_list, False, False)
|
||||||
|
|
||||||
account_dir = acct_dir(base_dir, nickname, domain)
|
account_dir = acct_dir(base_dir, nickname, domain)
|
||||||
with open(account_dir + '/followers.txt', 'r',
|
foll_list: list[str] = \
|
||||||
encoding='utf-8') as fp_foll:
|
load_list(account_dir + '/followers.txt',
|
||||||
for follower_domain in fp_foll:
|
'EX: _test_follows load list ' +
|
||||||
test_domain = follower_domain.split('@')[1]
|
account_dir + '/followers.txt')
|
||||||
test_domain = remove_eol(test_domain)
|
for follower_domain in foll_list:
|
||||||
if test_domain not in federation_list:
|
test_domain = follower_domain.split('@')[1]
|
||||||
print(test_domain)
|
test_domain = remove_eol(test_domain)
|
||||||
assert False
|
if test_domain not in federation_list:
|
||||||
|
print(test_domain)
|
||||||
|
assert False
|
||||||
|
|
||||||
os.chdir(curr_dir)
|
os.chdir(curr_dir)
|
||||||
shutil.rmtree(base_dir, ignore_errors=False)
|
shutil.rmtree(base_dir, ignore_errors=False)
|
||||||
|
|
@ -3401,8 +3414,8 @@ def test_client_to_server(base_dir: str):
|
||||||
print('Bob follows the calendar of Alice')
|
print('Bob follows the calendar of Alice')
|
||||||
following_cal_path = \
|
following_cal_path = \
|
||||||
data_dir(bob_dir) + '/bob@' + bob_domain + '/followingCalendar.txt'
|
data_dir(bob_dir) + '/bob@' + bob_domain + '/followingCalendar.txt'
|
||||||
with open(following_cal_path, 'w+', encoding='utf-8') as fp_foll:
|
save_string('alice@' + alice_domain + '\n', following_cal_path,
|
||||||
fp_foll.write('alice@' + alice_domain + '\n')
|
'EX: test_client_to_server save ' + following_cal_path)
|
||||||
|
|
||||||
print('\n\n*******************************************************')
|
print('\n\n*******************************************************')
|
||||||
print('EVENT: Alice sends to Bob via c2s')
|
print('EVENT: Alice sends to Bob via c2s')
|
||||||
|
|
@ -4868,9 +4881,10 @@ def _test_translation_labels() -> None:
|
||||||
continue
|
continue
|
||||||
if source_file.startswith('flycheck_'):
|
if source_file.startswith('flycheck_'):
|
||||||
continue
|
continue
|
||||||
source_str = ''
|
source_str: str = \
|
||||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
load_string(source_file,
|
||||||
source_str = fp_source.read()
|
'EX: _test_translation_labels load ' +
|
||||||
|
source_file)
|
||||||
if not source_str:
|
if not source_str:
|
||||||
continue
|
continue
|
||||||
if 'translate[' not in source_str:
|
if 'translate[' not in source_str:
|
||||||
|
|
@ -5520,8 +5534,8 @@ def _diagram_groups(include_groups: [],
|
||||||
for group_name in include_groups:
|
for group_name in include_groups:
|
||||||
filename += '_' + group_name.replace(' ', '-')
|
filename += '_' + group_name.replace(' ', '-')
|
||||||
filename += '.dot'
|
filename += '.dot'
|
||||||
with open(filename, 'w+', encoding='utf-8') as fp_graph:
|
if save_string(call_graph_str, filename,
|
||||||
fp_graph.write(call_graph_str)
|
'EX: _diagram_groups save ' + filename):
|
||||||
print('Graph saved to ' + filename)
|
print('Graph saved to ' + filename)
|
||||||
print('Plot using: ' +
|
print('Plot using: ' +
|
||||||
'sfdp -x -Goverlap=false -Goverlap_scaling=2 ' +
|
'sfdp -x -Goverlap=false -Goverlap_scaling=2 ' +
|
||||||
|
|
@ -5539,9 +5553,10 @@ def _test_post_variable_names():
|
||||||
continue
|
continue
|
||||||
if source_file.startswith('flycheck_'):
|
if source_file.startswith('flycheck_'):
|
||||||
continue
|
continue
|
||||||
source_str = ''
|
source_str: str = \
|
||||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
load_string(source_file,
|
||||||
source_str = fp_source.read()
|
'EX: _test_post_variable_names load ' +
|
||||||
|
source_file)
|
||||||
if not source_str:
|
if not source_str:
|
||||||
continue
|
continue
|
||||||
if ' name="' not in source_str:
|
if ' name="' not in source_str:
|
||||||
|
|
@ -5574,9 +5589,10 @@ def _test_config_param_names():
|
||||||
continue
|
continue
|
||||||
if source_file.startswith('flycheck_'):
|
if source_file.startswith('flycheck_'):
|
||||||
continue
|
continue
|
||||||
source_str = ''
|
source_str: str = \
|
||||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
load_string(source_file,
|
||||||
source_str = fp_source.read()
|
'EX: _test_config_param_names load ' +
|
||||||
|
source_file)
|
||||||
if not source_str:
|
if not source_str:
|
||||||
continue
|
continue
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
|
|
@ -5622,9 +5638,10 @@ def _test_source_contains_no_tabs():
|
||||||
continue
|
continue
|
||||||
if source_file.startswith('flycheck_'):
|
if source_file.startswith('flycheck_'):
|
||||||
continue
|
continue
|
||||||
source_str = ''
|
source_str: str = \
|
||||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
load_string(source_file,
|
||||||
source_str = fp_source.read()
|
'EX: _test_source_contains_no_tabs load ' +
|
||||||
|
source_file)
|
||||||
if not source_str:
|
if not source_str:
|
||||||
continue
|
continue
|
||||||
if '\t' in source_str:
|
if '\t' in source_str:
|
||||||
|
|
@ -5649,9 +5666,10 @@ def _test_checkbox_names():
|
||||||
continue
|
continue
|
||||||
if source_file.startswith('flycheck_'):
|
if source_file.startswith('flycheck_'):
|
||||||
continue
|
continue
|
||||||
source_str = ''
|
source_str: str = \
|
||||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
load_string(source_file,
|
||||||
source_str = fp_source.read()
|
'EX: _test_checkbox_names load ' +
|
||||||
|
source_file)
|
||||||
if not source_str:
|
if not source_str:
|
||||||
continue
|
continue
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
|
|
@ -5689,9 +5707,9 @@ def _test_post_field_names(source_file: str, fieldnames: []):
|
||||||
for field in fieldnames:
|
for field in fieldnames:
|
||||||
fnames.append(field + '.get')
|
fnames.append(field + '.get')
|
||||||
|
|
||||||
source_str = ''
|
source_str: str = \
|
||||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
load_string(source_file,
|
||||||
source_str = fp_source.read()
|
'EX: _test_post_field_names load ' + source_file)
|
||||||
if not source_str:
|
if not source_str:
|
||||||
return
|
return
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
|
|
@ -5773,9 +5791,10 @@ def _test_thread_functions():
|
||||||
modules[mod_name] = {
|
modules[mod_name] = {
|
||||||
'functions': []
|
'functions': []
|
||||||
}
|
}
|
||||||
source_str = ''
|
source_str: str = \
|
||||||
with open(source_file, 'r', encoding='utf-8') as fp_src:
|
load_string(source_file,
|
||||||
source_str = fp_src.read()
|
'EX: load ' + source_file)
|
||||||
|
if source_str:
|
||||||
modules[mod_name]['source'] = source_str
|
modules[mod_name]['source'] = source_str
|
||||||
if 'thread_with_trace(' in source_str:
|
if 'thread_with_trace(' in source_str:
|
||||||
threads_called_in_modules.append(mod_name)
|
threads_called_in_modules.append(mod_name)
|
||||||
|
|
@ -5936,7 +5955,9 @@ def _test_functions():
|
||||||
'functions': []
|
'functions': []
|
||||||
}
|
}
|
||||||
# load the module source
|
# load the module source
|
||||||
source_str: str = load_string(source_file, '')
|
source_str: str = \
|
||||||
|
load_string(source_file, 'EX: test_functions load ' +
|
||||||
|
source_file)
|
||||||
modules[mod_name]['source'] = source_str
|
modules[mod_name]['source'] = source_str
|
||||||
# go through the source line by line
|
# go through the source line by line
|
||||||
lines: list[str] = load_list(source_file, '')
|
lines: list[str] = load_list(source_file, '')
|
||||||
|
|
@ -6123,9 +6144,8 @@ def _test_functions():
|
||||||
'sed -i "s|' + name + '|' + snake_case_name + '|g" *.py\n'
|
'sed -i "s|' + name + '|' + snake_case_name + '|g" *.py\n'
|
||||||
ctr += 1
|
ctr += 1
|
||||||
print(function_names_str + '\n')
|
print(function_names_str + '\n')
|
||||||
with open('scripts/bad_function_names.sh', 'w+',
|
save_string(function_names_sh, 'scripts/bad_function_names.sh',
|
||||||
encoding='utf-8') as fp_file:
|
'EX: scripts/bad_function_names.sh')
|
||||||
fp_file.write(function_names_sh)
|
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
# which modules is each function used within?
|
# which modules is each function used within?
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue