Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F56547619
test_snippet_helper.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Mar 29, 00:38
Size
1 KB
Mime Type
text/x-c
Expires
Sun, Mar 31, 00:38 (2 d)
Engine
blob
Format
Raw Data
Handle
16722318
Attached To
R3683 Slides
test_snippet_helper.py
View Options
#!/bin/env python3
from
__future__
import
print_function
import
unittest
try
:
from
Slides
import
snippet_helper
as
sh
except
:
pass
class
SnippetHelperTest
(
unittest
.
TestCase
):
"Unit tests for SnippetHelper"
def
setUp
(
self
,
):
pass
def
test_cpp_snippet_from_file
(
self
):
sh
.
Snippet
.
default_line_number
=
True
snip
=
sh
.
Snippet
(
'tests/snippet.cpp'
)
snip
.
save
(
'snippet2.cpp'
)
f
=
open
(
'snippet2.cpp'
)
snip2
=
f
.
read
()
f
.
close
()
if
snip
.
get_content
()
!=
snip2
:
print
(
'AAA '
,
snip
.
get_content
())
print
(
'BBB '
,
snip2
)
raise
RuntimeError
(
'failed test'
)
def
test_cpp_snippet_format
(
self
):
sh
.
Snippet
.
default_line_number
=
True
code
=
"""
#include <iostream>
int main(int argc, char **argv){
return 0;
}
"""
code
=
code
.
replace
(
';
\n
'
,
';'
)
snip
=
sh
.
Snippet
(
code
,
format_flag
=
True
)
snip
.
save
(
'snippet2.cpp'
)
f
=
open
(
'snippet2.cpp'
)
snip2
=
f
.
read
()
f
.
close
()
self
.
assertEqual
(
snip
.
get_content
(),
snip2
)
self
.
assertNotEqual
(
snip
.
get_content
(),
code
)
def
test_cpp_snippet_compile_fail
(
self
):
sh
.
Snippet
.
default_line_number
=
True
code
=
"""
#include <iostream>
int main(int argc, char **argv){
return 0
}
"""
code
=
code
.
replace
(
';
\n
'
,
';'
)
try
:
sh
.
Snippet
(
code
,
compile_flag
=
True
)
self
.
fail
(
"compilation error not detected"
)
except
sh
.
Snippet
.
CompilationError
as
e
:
pass
except
Exception
as
e
:
self
.
fail
(
'wrong exception:'
+
str
(
e
))
def
test_cpp_snippet_compile
(
self
):
sh
.
Snippet
.
default_line_number
=
True
code
=
"""
#include <iostream>
int main(int argc, char **argv){
return 0;
}
"""
code
=
code
.
replace
(
';
\n
'
,
';'
)
try
:
sh
.
Snippet
(
code
,
compile_flag
=
True
)
except
Exception
as
e
:
self
.
fail
(
'should compile: '
+
str
(
e
))
Event Timeline
Log In to Comment