Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
fe7effd5
Commit
fe7effd5
authored
May 19, 2019
by
Egor Dranischnikow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding further test cases, testing the behavior of parse_directives and parse_options
parent
774924bf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
0 deletions
+108
-0
Cython/Build/Tests/TestCythonizeArgsParser.py
Cython/Build/Tests/TestCythonizeArgsParser.py
+108
-0
No files found.
Cython/Build/Tests/TestCythonizeArgsParser.py
View file @
fe7effd5
...
...
@@ -25,6 +25,7 @@ class TestCythonizeArgsParser(TestCase):
return
False
return
True
# testing directives:
def
test_directive_short
(
self
):
options
,
args
=
self
.
parse_args
([
'-X'
,
'cdivision=True'
])
self
.
assertFalse
(
args
)
...
...
@@ -51,6 +52,64 @@ class TestCythonizeArgsParser(TestCase):
self
.
assertEqual
(
options
.
directives
[
'cdivision'
],
True
)
self
.
assertEqual
(
options
.
directives
[
'c_string_type'
],
'bytes'
)
def
test_directive_value_yes
(
self
):
options
,
args
=
self
.
parse_args
([
'-X'
,
'cdivision=YeS'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'directives'
]))
self
.
assertEqual
(
options
.
directives
[
'cdivision'
],
True
)
def
test_directive_value_no
(
self
):
options
,
args
=
self
.
parse_args
([
'-X'
,
'cdivision=no'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'directives'
]))
self
.
assertEqual
(
options
.
directives
[
'cdivision'
],
False
)
def
test_directive_value_invalid
(
self
):
with
self
.
assertRaises
(
ValueError
)
as
context
:
options
,
args
=
self
.
parse_args
([
'-X'
,
'cdivision=sadfasd'
])
def
test_directive_key_invalid
(
self
):
with
self
.
assertRaises
(
ValueError
)
as
context
:
options
,
args
=
self
.
parse_args
([
'-X'
,
'abracadabra'
])
def
test_directive_no_value
(
self
):
with
self
.
assertRaises
(
ValueError
)
as
context
:
options
,
args
=
self
.
parse_args
([
'-X'
,
'cdivision'
])
def
test_directives_types
(
self
):
directives
=
{
'auto_pickle'
:
True
,
'c_string_type'
:
'bytearray'
,
'c_string_type'
:
'bytes'
,
'c_string_type'
:
'str'
,
'c_string_type'
:
'bytearray'
,
'c_string_type'
:
'unicode'
,
'c_string_encoding'
:
'ascii'
,
'language_level'
:
2
,
'language_level'
:
3
,
'language_level'
:
'3str'
,
'set_initial_path'
:
'my_initial_path'
,
}
for
key
,
value
in
directives
.
items
():
cmd
=
'{key}={value}'
.
format
(
key
=
key
,
value
=
str
(
value
))
options
,
args
=
self
.
parse_args
([
'-X'
,
cmd
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'directives'
]),
msg
=
"Error for option: "
+
cmd
)
self
.
assertEqual
(
options
.
directives
[
key
],
value
,
msg
=
"Error for option: "
+
cmd
)
def
test_directives_wrong
(
self
):
directives
=
{
'auto_pickle'
:
42
,
# for bool type
'auto_pickle'
:
'NONONO'
,
# for bool type
'c_string_type'
:
'bites'
,
#'c_string_encoding' : 'a',
#'language_level' : 4,
}
for
key
,
value
in
directives
.
items
():
cmd
=
'{key}={value}'
.
format
(
key
=
key
,
value
=
str
(
value
))
with
self
.
assertRaises
(
ValueError
,
msg
=
"Error for option: "
+
cmd
)
as
context
:
options
,
args
=
self
.
parse_args
([
'-X'
,
cmd
])
def
test_compile_time_env_short
(
self
):
options
,
args
=
self
.
parse_args
([
'-E'
,
'MYSIZE=10'
])
self
.
assertFalse
(
args
)
...
...
@@ -77,6 +136,7 @@ class TestCythonizeArgsParser(TestCase):
self
.
assertEqual
(
options
.
compile_time_env
[
'MYSIZE'
],
10
)
self
.
assertEqual
(
options
.
compile_time_env
[
'ARRSIZE'
],
11
)
#testing options
def
test_option_short
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'docstrings=True'
])
self
.
assertFalse
(
args
)
...
...
@@ -103,6 +163,54 @@ class TestCythonizeArgsParser(TestCase):
self
.
assertEqual
(
options
.
options
[
'docstrings'
],
True
)
self
.
assertEqual
(
options
.
options
[
'buffer_max_dims'
],
True
)
# really?
def
test_option_value_yes
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'docstrings=YeS'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'options'
]))
self
.
assertEqual
(
options
.
options
[
'docstrings'
],
True
)
def
test_option_value_4242
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'docstrings=4242'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'options'
]))
self
.
assertEqual
(
options
.
options
[
'docstrings'
],
True
)
def
test_option_value_0
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'docstrings=0'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'options'
]))
self
.
assertEqual
(
options
.
options
[
'docstrings'
],
False
)
def
test_option_value_emptystr
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'docstrings='
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'options'
]))
self
.
assertEqual
(
options
.
options
[
'docstrings'
],
True
)
def
test_option_value_a_str
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'docstrings=BB'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'options'
]))
self
.
assertEqual
(
options
.
options
[
'docstrings'
],
True
)
def
test_option_value_no
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'docstrings=nO'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'options'
]))
self
.
assertEqual
(
options
.
options
[
'docstrings'
],
False
)
def
test_option_no_value
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'docstrings'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'options'
]))
self
.
assertEqual
(
options
.
options
[
'docstrings'
],
True
)
def
test_option_any_key
(
self
):
options
,
args
=
self
.
parse_args
([
'-s'
,
'abracadabra'
])
self
.
assertFalse
(
args
)
self
.
assertTrue
(
self
.
are_default
(
options
,
[
'options'
]))
self
.
assertEqual
(
options
.
options
[
'abracadabra'
],
True
)
def
test_language_level_2
(
self
):
options
,
args
=
self
.
parse_args
([
'-2'
])
self
.
assertFalse
(
args
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment