Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
lm-evaluation-harness
Commits
377a4fe2
Unverified
Commit
377a4fe2
authored
Nov 26, 2021
by
Leo Gao
Committed by
GitHub
Nov 26, 2021
Browse files
pytest.approx doesn't support recursive dicts
parent
a3d99617
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 deletion
+13
-1
tests/test_version_stable.py
tests/test_version_stable.py
+13
-1
No files found.
tests/test_version_stable.py
View file @
377a4fe2
...
...
@@ -6,6 +6,7 @@ import pytest
import
os
import
json
import
hashlib
import
collections
os
.
makedirs
(
"tests/testdata"
,
exist_ok
=
True
)
...
...
@@ -15,7 +16,7 @@ def assert_target(name, ob):
fname
=
f
"tests/testdata/
{
name
}
.json"
if
os
.
path
.
exists
(
fname
):
with
open
(
fname
)
as
fh
:
assert
json
.
load
(
fh
)
==
pytest
.
approx
(
json
.
loads
(
json
.
dumps
(
ob
,
sort_keys
=
True
)))
assert
flatten
(
json
.
load
(
fh
)
)
==
pytest
.
approx
(
flatten
(
json
.
loads
(
json
.
dumps
(
ob
,
sort_keys
=
True
)))
)
else
:
with
open
(
fname
,
'w'
)
as
fh
:
json
.
dump
(
ob
,
fh
,
sort_keys
=
True
)
...
...
@@ -29,6 +30,17 @@ def assert_target_hashed(name, ob):
with
open
(
fname
,
'w'
)
as
fh
:
fh
.
write
(
hashlib
.
sha256
(
json
.
dumps
(
ob
,
sort_keys
=
True
).
encode
(
'utf-8'
)).
hexdigest
())
# from https://stackoverflow.com/a/6027615
def
flatten
(
d
,
parent_key
=
''
,
sep
=
'.'
):
items
=
[]
for
k
,
v
in
d
.
items
():
new_key
=
parent_key
+
sep
+
k
if
parent_key
else
k
if
isinstance
(
v
,
collections
.
MutableMapping
):
items
.
extend
(
flatten
(
v
,
new_key
,
sep
=
sep
).
items
())
else
:
items
.
append
((
new_key
,
v
))
return
dict
(
items
)
# make sure eval results for a task version are stable
...
...
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