[python] test: check wether script execution lead to a Python error

This commit is contained in:
Émilie Feral
2020-04-01 13:51:13 +02:00
committed by LeaNumworks
parent 2f171eb2fd
commit 2738d30684
6 changed files with 37 additions and 25 deletions

View File

@@ -5,7 +5,6 @@ static const char * s_pyplotArrowScript = R"(#
from matplotlib.pyplot import *
arrow(2,3,4,5)
show()
print('ok')
)";
static const char * s_pyplotAxisScript = R"(#
@@ -15,13 +14,11 @@ axis([2,3,4,5])
print(axis())
scatter(0,1)
show()
print('ok')
)";
static const char * s_pyplotAxisErrorScript = R"(#
from matplotlib.pyplot import *
axis(2,3,4,5)
print('fail!')
)";
static const char * s_pyplotBarScript = R"(#
@@ -32,14 +29,12 @@ bar([],[])
bar([1,2,3],[1,2,3],2,3)
bar([1,2,3],[1,2,3],[1,2,3],[1,2,3])
show()
print('ok')
)";
static const char * s_pyplotBarErrorScript = R"(#
from matplotlib.pyplot import *
bar([1,2,3],[1,2,3,4],[1,2,3],[1,2,3])
show()
print('fail!')
)";
static const char * s_pyplotGridScript = R"(#
@@ -47,7 +42,6 @@ from matplotlib.pyplot import *
grid(True)
grid()
show()
print('ok')
)";
static const char * s_pyplotHistScript = R"(#
@@ -57,7 +51,6 @@ hist([2,3,4,5,6],23)
hist([2,3,4,5,6],[0,2,3])
hist([2,3,4,5,6],[0,2,3, 4,5,6,7])
show()
print('ok')
)";
static const char * s_pyplotPlotScript = R"(#
@@ -65,13 +58,11 @@ from matplotlib.pyplot import *
plot([2,3,4,5,6])
plot([2,3,4,5,6],[3,4,5,6,7])
show()
print('ok')
)";
static const char * s_pyplotPlotErrorScript = R"(#
from matplotlib.pyplot import *
plot([2,3,4,5,6],2)
print('Fail!')
)";
static const char * s_pyplotScatterScript = R"(#
@@ -79,33 +70,30 @@ from matplotlib.pyplot import *
scatter(2,3)
scatter([2,3,4,5,6],[3,4,5,6,7])
show()
print('ok')
)";
static const char * s_pyplotScatterErrorScript = R"(#
from matplotlib.pyplot import *
scatter([2,3,4,5,6],2)
print('Fail!')
)";
static const char * s_pyplotTextScript = R"(#
from matplotlib.pyplot import *
text(2,3, "hello")
text(2,3,'hello')
show()
print('ok')
)";
QUIZ_CASE(python_matplotlib_pyplot) {
assert_script_execution_succeeds(s_pyplotArrowScript);
assert_script_execution_succeeds(s_pyplotAxisScript);
assert_script_execution_succeeds(s_pyplotAxisErrorScript);
assert_script_execution_succeeds(s_pyplotAxisScript, "(2.0, 3.0, 4.0, 5.0)\n");
assert_script_execution_fails(s_pyplotAxisErrorScript);
assert_script_execution_succeeds(s_pyplotBarScript);
assert_script_execution_succeeds(s_pyplotBarErrorScript);
assert_script_execution_fails(s_pyplotBarErrorScript);
assert_script_execution_succeeds(s_pyplotGridScript);
assert_script_execution_succeeds(s_pyplotHistScript);
assert_script_execution_succeeds(s_pyplotPlotScript);
assert_script_execution_succeeds(s_pyplotPlotErrorScript);
assert_script_execution_fails(s_pyplotPlotErrorScript);
assert_script_execution_succeeds(s_pyplotScatterScript);
assert_script_execution_succeeds(s_pyplotScatterErrorScript);
assert_script_execution_fails(s_pyplotScatterErrorScript);
assert_script_execution_succeeds(s_pyplotTextScript);
}