Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deviser tests documentation #41

Merged
merged 64 commits into from
Jan 21, 2021
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
d069815
A little simplification.
Dec 15, 2020
6ea87b2
Documenting functions in run_matlab_tests.py.
Dec 15, 2020
31103f5
Tidyin gup a bit and adding function docstring.
Dec 15, 2020
2985780
A bit more tidying.
Dec 15, 2020
7129b69
Replace global_variables with gv.
Dec 15, 2020
9d328a5
Started documenting test_functions.py.
Dec 15, 2020
08b3d3b
Added more docstrings to test_functions.py.
Dec 15, 2020
a6818ca
A little bit of tidying up.
Dec 15, 2020
2c37c22
Took out some common code.
Dec 16, 2020
4fd9bc7
Using os.path.normpath() means a file path should work on both Window…
Dec 16, 2020
70abf42
Now we can run more tests.
Dec 16, 2020
92e97b4
More meaningful function name. Some tidying.
Dec 17, 2020
f128fa1
I've added docstrings to the functions I understand.
Dec 17, 2020
84a3ac8
Final comment for now.
Dec 17, 2020
74f1260
Using os.path.normpath() means this should work on Windows and *nix.
Dec 17, 2020
ec85fe2
Extract common code into setup().
Dec 17, 2020
cdd8a3f
Now we have a common compare function.
Dec 17, 2020
32a8e3c
More generic functions to replace specifics.
Dec 17, 2020
01fc802
Finished documenting run_text_tests.py.
Dec 17, 2020
1071fac
Adding os.path.normpath() lets us run the tsts on Windows and *nix.
Dec 17, 2020
bc23d8f
Extracted common set-up code into its own function.
Dec 17, 2020
b15acc2
Removed wrapper function around test_functions.compare_files().
Dec 17, 2020
bd23dd7
Added some docstrings.
Dec 17, 2020
f2cae72
Added what docstrings I can.
Dec 17, 2020
503e097
Added more text and TODO statements.
Jan 5, 2021
c546a49
Used os.path.normpath() for portability.
Jan 6, 2021
d17e055
Finished most of the basic documentation for run_cmake_tests.py.
Jan 6, 2021
a3c5485
Fixed some of the flake8 complaints.
Jan 6, 2021
abe41fb
Added more os.path.normpath() statements.
Jan 6, 2021
da46fb9
Added more os.path.normpath() statements to run_examples_tests.py, bu…
Jan 6, 2021
31ca25c
Added some os.path.normpath() statements to run_matlab_tests.py
Jan 6, 2021
5731835
Added os.path.normpath() statements to run_cpp_tests.py
Jan 6, 2021
57f005c
Moving always-run tests to beginning of test set.
Jan 6, 2021
3a81c58
Abstracted some common code into generate_generic_header().
Jan 6, 2021
a39cf9f
Extracted common code into common_setup().
Jan 6, 2021
5e215b9
More function documenting in run_cpp_tests.py
Jan 6, 2021
d2461db
Moving common code into new version of compare_files().
Jan 6, 2021
36fc367
Added more documentation to the comparison functions.
Jan 6, 2021
edbd39d
Added docs to the test runner functions.
Jan 6, 2021
56315bf
Ran all cpp test files through dos2unix so python 2 tests will succeed.
Jan 6, 2021
e45e104
Added explanatory note about dos2unix etc.
Jan 6, 2021
61b8ad5
Fixed some typos and flake8 complaints.
Jan 7, 2021
32e6dbb
Added os.path.normpath() statements to make the code portable.
Jan 7, 2021
1efd1ca
Moved a lot of duplicate code into new function common_set_up().
Jan 7, 2021
82abddd
Moved some common code into new function go_into_new_directory().
Jan 7, 2021
9844227
Took out some more common code.
Jan 7, 2021
4ee0b16
Took out some more common code into new comparison functions.
Jan 7, 2021
6ec4c25
import global_variables as gv
Jan 7, 2021
8603651
Fixed a bug. Noted some failed and skipped tests.
Jan 7, 2021
2e36afc
Stopped most tests skipping.
Jan 7, 2021
3270d82
Now we are no longer skipping tests.
Jan 7, 2021
bbe51fb
Now we are missing only two files.
Jan 7, 2021
03d9979
Now no files are missing.
Jan 11, 2021
2a8e90d
Started documenting run_other_library_tests.py
Jan 11, 2021
d59fd67
Removed unused function parameter.
Jan 11, 2021
9035473
Added more docstrings, and also queries.
Jan 11, 2021
15d895a
I think this is as much as I can do with this file.
Jan 12, 2021
e119943
added some explanations
skeating Jan 15, 2021
80f3d34
added explanation
skeating Jan 15, 2021
9ee5153
oops forgot to change param in code
skeating Jan 15, 2021
3c4dc4e
note that files are not yet part of testing
skeating Jan 15, 2021
40b3149
Adding Sarah's PR comments etc.
Jan 18, 2021
4c48705
Merge branch 'develop' into matt-tests
Jan 18, 2021
6b82a4f
Hopefully fixing the last of Sarah's required changes for PR 41
Jan 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Started documenting run_other_library_tests.py
Matthew Gillman committed Jan 11, 2021
commit 2a8e90d4dde8fd171514f51bdb1acf4a9b2ee38e
147 changes: 112 additions & 35 deletions generator/tests/test_other_library/run_other_library_tests.py
Original file line number Diff line number Diff line change
@@ -20,19 +20,7 @@


##############################################################################
# Specific generation functions


def generate_new_cpp_header(filename, num):
ob = common_set_up(filename)
working_class = ob['baseElements'][num]
if working_class['name'] == gv.document_class:
working_class['document'] = True
go_into_new_directory()
all_files = CppFiles.CppFiles(working_class, True)
all_files.write_files()
os.chdir('../../.')

# Utility functions

def common_set_up(filename):
"""
@@ -53,7 +41,7 @@ def common_set_up(filename):

def go_into_new_directory():
"""
Create the new directory if required. Go into it.
Create the new ./temp directory if required. Go into it.
"""
os.chdir('./temp')
new_dir = gv.language
@@ -62,7 +50,35 @@ def go_into_new_directory():
os.chdir(new_dir)


##############################################################################
# Specific generation functions


def generate_new_cpp_header(filename, num):
"""
Generate new C++ header and code files.

:param filename: the XML file to parse.
:param num: TODO not too sure about this - it's a list index.
:return: nothing
"""
ob = common_set_up(filename)
working_class = ob['baseElements'][num]
if working_class['name'] == gv.document_class:
working_class['document'] = True
go_into_new_directory()
all_files = CppFiles.CppFiles(working_class, True)
all_files.write_files()
os.chdir('../../.')


def generate_templates(filename):
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several of the files for other libraries are generated using templates with appropriate names etc added.
See generator/code_files/templates
This function tests these

TODO not sure what this does. Not sure what ValidationFiles class is for.

:param filename: the XML file to parse.
:return: nothing
"""
ob = common_set_up(filename)
gv.populate_error_list(ob)
ValidationFiles.ValidationFiles(ob, True)
@@ -75,6 +91,12 @@ def generate_templates(filename):


def generate_common_templates(filename):
"""
Write the 'common' files. TODO need more explanation.

:param filename: the XML file to parse.
:return: nothing
"""
ob = common_set_up(filename)
gv.populate_error_list(ob)
go_into_new_directory()
@@ -86,6 +108,12 @@ def generate_common_templates(filename):


def generate_forward(filename):
"""
Write extension file with forward declaration of all opaque C types.

:param filename: the XML file to parse.
:return: nothing
"""
ob = common_set_up(filename)
gv.populate_error_list(ob)
go_into_new_directory()
@@ -96,6 +124,13 @@ def generate_forward(filename):


def generate_enum(filename):
"""
According to ExtensionFile.py, this writes the extension types file.
TODO what does that mean?

:param filename: the XML file to parse.
:return: nothing
"""
ob = common_set_up(filename)
gv.populate_error_list(ob)
go_into_new_directory()
@@ -106,6 +141,13 @@ def generate_enum(filename):


def generate_binding(filename, binding):
"""
Generate the "binding" files.

:param filename: the XML file to parse.
:param binding: binding to use, e.g. 'swig', 'cmake', 'csharp'
:return: nothing
"""
ob = common_set_up(filename)
go_into_new_directory()

@@ -119,6 +161,13 @@ def generate_binding(filename, binding):


def generate_cmake(filename, binding):
"""
Write CMake files CMakeLists.txt

:param filename: the XML file to parse.
:param binding:
:return: nothing
"""
ob = common_set_up(filename)
go_into_new_directory()

@@ -139,6 +188,13 @@ def generate_cmake(filename, binding):


def generate_global(filename):
"""
Generate the global files required
e.g. VERSION.txt, README.md, LICENSE.txt.

:param filename: the XML file to parse.
:return: nothing
"""
common_set_up(filename) # Don't need ob!
go_into_new_directory()
generateCode.generate_global_files()
@@ -147,13 +203,28 @@ def generate_global(filename):
#############################################################################
# Specific compare functions


def compare_files(correct_file, temp_file):
"""
Wrapper function to compare two files: are they identical?

:param correct_file: the reference file we are comparing against
:param temp_file: temporary file generated by the test code.
:returns: 0 on success, or file not present; 1 on failure.
"""
return test_functions.compare_files(correct_file, temp_file, fails,
not_tested)

#########

def compare_code(class_name, end):
"""
Compare two "code" files. Are they identical?

:param class_name: name of C++ class used in the test.
:param end: file extension, e.g. ".h", ".txt", etc.
:returns: 0 on success, or file not present; 1 on failure.
"""
correct_file = os.path.normpath('./test-code/{1}/{0}{2}'.format(class_name, gv.language, end))
temp_file = os.path.normpath('./temp/{1}/{0}{2}'.format(class_name, gv.language, end))
return compare_files(correct_file, temp_file)
@@ -173,19 +244,26 @@ def compare_code_txt(class_name, ext='.txt'):
#########

def compare_binding(class_name, binding, end, prefix=""):
"""
Compare two "binding" files.

:param class_name: C++ class, e.g. "OStream"
:param binding: the language binding,e.g. "swig" or "csharp"
:param end: file extension, e.g. ".txt", ".cpp"
:param prefix: I don't think this is ever used in any function calls.
:returns: 0 on success, or file not present; 1 on failure.
"""
correct_file = os.path.normpath('./test-code/{2}/{0}/{1}{3}'.format(binding, class_name, gv.language, end))
#if prefix:
# if prefix:
temp_file = os.path.normpath('./temp/{3}/{0}/{2}/{1}{4}'.format(binding, class_name, prefix, gv.language, end))
#else:
#temp_file = os.path.normpath('./temp/{2}/{0}/{1}{3}'.format(binding, class_name, gv.language, end))
# else:
# temp_file = os.path.normpath('./temp/{2}/{0}/{1}{3}'.format(binding, class_name, gv.language, end))
return compare_files(correct_file, temp_file)


def compare_binding_headers(class_name, binding, prefix):
return compare_binding(class_name, binding, ".h", prefix)
# temp/omex/swig/combine/OStream.h=================>> MISSING
# temp/sedml/swig/sedml/OStream.h=================>> MISSING
# compare_binding_headers('OStream', binding is swig, prefix is sedml or combine??)
# present: temp/omex/swig/OStream.h and temp/sedml/swig/OStream.h


def compare_binding_impl(class_name, binding, prefix):
return compare_binding(class_name, binding, ".cpp", prefix)
@@ -201,7 +279,6 @@ def compare_binding_file(class_name, binding, prefix):
def compare_cmake_file(this_dir, prefix):
correct_file = os.path.normpath('./test-code/{0}/cmake/CMakeLists.txt'.format(gv.language))
temp_file = os.path.normpath('./temp/{1}/cmake/{0}/CMakeLists.txt'.format(this_dir, gv.language))
#temp_file = os.path.normpath('./temp/{0}/cmake/{0}/CMakeLists.txt'.format(gv.language))
return compare_files(correct_file, temp_file)

#############################################################################
@@ -292,20 +369,20 @@ def test_bindings(name, class_name, test_case, binding, prefix):
generate_binding(filename, binding)
fail = 0
if binding == 'swig':
fail += compare_binding_headers('ListWrapper', binding, "") #prefix)
fail += compare_binding_headers('OStream', binding, "") #prefix)
fail += compare_binding_impl('OStream', binding, "") #prefix)
fail += compare_binding_interface('std_set', binding, "") #prefix)
fail += compare_binding_headers('lib{0}'.format(prefix), binding, "") #prefix)
fail += compare_binding_interface('lib{0}'.format(prefix), binding, "") #prefix)
fail += compare_binding_interface('ASTNodes', binding, "") #prefix)
fail += compare_binding_headers('ListWrapper', binding, "")
fail += compare_binding_headers('OStream', binding, "")
fail += compare_binding_impl('OStream', binding, "")
fail += compare_binding_interface('std_set', binding, "")
fail += compare_binding_headers('lib{0}'.format(prefix), binding, "")
fail += compare_binding_interface('lib{0}'.format(prefix), binding, "")
fail += compare_binding_interface('ASTNodes', binding, "")
elif binding == 'csharp':
fail += compare_binding_impl('local', binding, "") #prefix)
fail += compare_binding_interface('local', binding, "") #prefix)
fail += compare_binding_interface('lib{0}'.format(prefix), binding, "") #prefix)
fail += compare_binding_file('CMakeLists.txt', binding, "") #prefix)
fail += compare_binding_file('compile-native-files.cmake', binding, "") #prefix)
fail += compare_binding_file('AssemblyInfo.cs.in', binding, "") #prefix)
fail += compare_binding_impl('local', binding, "")
fail += compare_binding_interface('local', binding, "")
fail += compare_binding_interface('lib{0}'.format(prefix), binding, "")
fail += compare_binding_file('CMakeLists.txt', binding, "")
fail += compare_binding_file('compile-native-files.cmake', binding, "")
fail += compare_binding_file('AssemblyInfo.cs.in', binding, "")
print('')
return fail