Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-pytoml
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-pytoml
Commits
3cc8cc19
Commit
3cc8cc19
authored
7 years ago
by
Michael Williamson
Browse files
Options
Downloads
Patches
Plain Diff
Raise error when dump is called with non-finite floats
parent
23afb8a9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pytoml/writer.py
+5
-2
5 additions, 2 deletions
pytoml/writer.py
test/test_writer.py
+15
-0
15 additions, 0 deletions
test/test_writer.py
with
20 additions
and
2 deletions
pytoml/writer.py
+
5
−
2
View file @
3cc8cc19
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
io
,
datetime
,
sys
import
io
,
datetime
,
math
,
sys
if
sys
.
version_info
[
0
]
==
3
:
if
sys
.
version_info
[
0
]
==
3
:
long
=
int
long
=
int
...
@@ -61,7 +61,10 @@ def _format_value(v):
...
@@ -61,7 +61,10 @@ def _format_value(v):
if
isinstance
(
v
,
int
)
or
isinstance
(
v
,
long
):
if
isinstance
(
v
,
int
)
or
isinstance
(
v
,
long
):
return
unicode
(
v
)
return
unicode
(
v
)
if
isinstance
(
v
,
float
):
if
isinstance
(
v
,
float
):
return
repr
(
v
)
if
math
.
isnan
(
v
)
or
math
.
isinf
(
v
):
raise
ValueError
(
"
{0} is not a valid TOML value
"
.
format
(
v
))
else
:
return
repr
(
v
)
elif
isinstance
(
v
,
unicode
)
or
isinstance
(
v
,
bytes
):
elif
isinstance
(
v
,
unicode
)
or
isinstance
(
v
,
bytes
):
return
_escape_string
(
v
)
return
_escape_string
(
v
)
elif
isinstance
(
v
,
datetime
.
datetime
):
elif
isinstance
(
v
,
datetime
.
datetime
):
...
...
This diff is collapsed.
Click to expand it.
test/test_writer.py
0 → 100644
+
15
−
0
View file @
3cc8cc19
from
__future__
import
unicode_literals
import
pytest
import
pytoml
as
toml
@pytest.mark.parametrize
(
"
value
"
,
[
float
(
"
NaN
"
),
float
(
"
Inf
"
),
-
float
(
"
Inf
"
),
])
def
test_attempting_to_write_non_number_floats_raises_error
(
value
):
error
=
pytest
.
raises
(
ValueError
,
lambda
:
toml
.
dumps
({
"
value
"
:
value
}))
assert
str
(
error
.
value
)
==
"
{0} is not a valid TOML value
"
.
format
(
value
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment