Take reorganiser.py
for example:
Generate re-organised source code:
λ> python reorganiser.py -d sample_inputs/dependency.py
Or
λ> python reorganiser.py sample_inputs/dependency.py
Generate original source code:
λ> python reorganiser.py -n sample_inputs/dependency.py
Note: The output of main.py
can now be handled in a similar way.
Take processor.py
for example:
Generate high level instructions:
λ> python processor.py -h sample_inputs/draw_house.py
Generate low level instructions:
λ> python processor.py -l sample_inputs/draw_house.py
Or
λ> python processor.py sample_inputs/draw_house.py
Note: The output of main.py
can now be handled in a similar way.
Take processor.py
for example:
Generate both instructions and statistics:
λ> python processor.py -b sample_inputs/draw_house.py
Or
λ> python processor.py sample_inputs/draw_house.py
Generate instructions only:
λ> python processor.py -i sample_inputs/draw_house.py
Generate statistics only:
λ> python processor.py -s sample_inputs/draw_house.py
Note: The output of main.py
can now be handled in a similar way.
-
define a new method named with the test_ prefix in the TestProcessor class of
test_processor.py
, which simplely calls the compare() method provided by the class. -
create a new python file with its basename the same as the method name in
unittest_inputs
, and add the python code for generating instructions into the file. -
create a new text file with its basename the same as the method name in
unittest_outputs
, and add the expected instructions for comparison into the file. -
run
test_processor.py
orunittest_coverage.sh
to compare the generated and expected instructions line by line.
There is a demo case for testing _Import(self, t) given in the project that you can refer to.
λ> python main.py sample_inputs/circle.py
[
{
"code": "import turtle",
"instruction": "Import the turtle module"
},
{
"code": "t = turtle.Turtle()",
"instruction": "Create and initialize variable 't' to return
value of function 'Turtle' on object 'turtle' without parameter"
},
{
"code": "for i in range(36):",
"instruction": "Iterate the variable i over the range from 0
to 36, and do the following:"
},
{
"code": " t.forward(10)",
"instruction": " Call function 'forward' on object 't' with
parameter of 10"
},
{
"code": " t.right(10)",
"instruction": " Call function 'right' on object 't' with
parameter of 10"
}
]