RestToCode_test.py - Unit testing¶
This test bench exercises the CodeToRest module. First, set up for
development (see To package). To run, execute py.test
from the
command line. Note the period in this command – pytest
does NOT work
(it is a completely different program).
Imports¶
These are listed in the order prescribed by PEP 8.
Third-party imports¶
Used to run docutils.
Local application imports¶
The string that results from rest_to_code not understanding the material.
Error testing main code
def et(
self,
rest,
alias_seq=(
"C",
"C",
"C++",
"Java",
"ActionScript",
"C#",
"D",
"Go",
"JavaScript",
"Objective-C",
"Rust",
"Scala",
"Swift",
"verilog",
"systemverilog",
"Dart",
"Juttle",
"Objective-J",
"TypeScript",
"Arduino",
"Clay",
"CUDA",
"eC",
"MQL",
"nesC",
"Pike",
"SWIG",
"Vala",
"Zephir",
"Haxe",
),
):
for alias in alias_seq:
code = rest_to_code_string(rest, alias)
assert code == error_str
def test_1(self):
self.et("hello")
def test_2(self):
self.et("\n" ".. fenced-code::\n" "\n" " Beginning fene\n")
class TestRestToCodeString(object):
def mt(self, given_code, expected_code, lang):
rest = code_to_rest_string(given_code, alias=lang)
code = rest_to_code_string(rest, lang)
assert code == expected_code
Inline comment to code transition
Single line block comment to code transition
Single line block comment to code transition No inline delimiters
Multi-line block comment to code transition
Multi-line block comment to code transition, no inline delimiters.
<div>
testing
<div>
testing, no inline delimiters
Round trip testing in files with a given name
Get the extension of the given file so you can match it with the temporary files.
Create the ‘temporary files <https://docs.python.org/3/library/tempfile.html#tempfile.mkstemp>’_.
Close all files. This is done on an os level because the os thinks they are open. The files are opened in python during the translation process so they needed to be closed first.
Translate the code to rest and back again twice. This will ensure that it is round trip stable.
Open and read the two code files.
Remove the temporary files from the system.
Make sure the code is the same; this shows round trip stability.
Python file test
CSS file test
Empty file (C) test
find_file_ext test
TODO.