Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F59806753
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
Thu, Apr 25, 08:32
Size
1 KB
Mime Type
text/x-c
Expires
Sat, Apr 27, 08:32 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17249541
Attached To
R3683 Slides
test_snippet_helper.py
View Options
#!/bin/env python3
# -*- coding: utf-8 -*-
from
Slides
import
snippet_helper
as
sh
def
test_cpp_snippet_from_file
():
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
():
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
()
assert
snip
.
get_content
()
==
snip2
assert
not
snip
.
get_content
()
==
code
def
test_cpp_snippet_compile_fail
():
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
)
raise
RuntimeError
(
"compilation error not detected"
)
except
sh
.
Snippet
.
CompilationError
as
e
:
pass
except
Exception
as
e
:
raise
RuntimeError
(
'wrong exception:'
+
str
(
e
))
def
test_cpp_snippet_compile
():
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
:
raise
RuntimeError
(
'should compile: '
+
str
(
e
))
Event Timeline
Log In to Comment