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
a3a2152c
Commit
a3a2152c
authored
Feb 01, 2021
by
Leo Gao
Browse files
Add unit tests
parent
8bd843c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
tests/test_all_sanitycheck.py
tests/test_all_sanitycheck.py
+51
-0
No files found.
tests/test_all_sanitycheck.py
0 → 100644
View file @
a3a2152c
import
lm_eval.tasks
as
tasks
import
lm_eval.base
as
base
from
unittest.mock
import
MagicMock
from
itertools
import
islice
import
pytest
@
pytest
.
mark
.
parametrize
(
"taskname,Task"
,
tasks
.
TASK_REGISTRY
.
items
())
def
test_basic_interface
(
taskname
,
Task
):
print
(
'Evaluating task'
,
taskname
)
dl
=
Task
.
download
Task
.
download
=
MagicMock
()
task
=
Task
()
Task
.
download
=
dl
assert
task
.
has_training_docs
()
in
[
True
,
False
]
assert
task
.
has_validation_docs
()
in
[
True
,
False
]
assert
task
.
has_test_docs
()
in
[
True
,
False
]
assert
isinstance
(
task
.
aggregation
(),
dict
)
assert
isinstance
(
task
.
higher_is_better
(),
dict
)
assert
task
.
aggregation
().
keys
()
==
task
.
higher_is_better
().
keys
()
for
v
in
task
.
higher_is_better
().
values
():
assert
v
in
[
True
,
False
]
@
pytest
.
mark
.
parametrize
(
"taskname,Task"
,
tasks
.
TASK_REGISTRY
.
items
())
def
test_documents_and_requests
(
taskname
,
Task
):
print
(
'Evaluating task'
,
taskname
)
task
=
Task
()
fns
=
[]
if
task
.
has_training_docs
():
fns
.
append
(
task
.
training_docs
)
if
task
.
has_validation_docs
():
fns
.
append
(
task
.
validation_docs
)
# test doce might not have labels
#if task.has_test_docs(): fns.append(task.test_docs)
for
fn
in
fns
:
#print(list(islice(fn(), 10)))
for
doc
in
islice
(
fn
(),
10
):
txt
=
task
.
doc_to_text
(
doc
)
tgt
=
task
.
doc_to_target
(
doc
)
assert
isinstance
(
txt
,
str
)
assert
isinstance
(
tgt
,
str
)
reqs
=
task
.
construct_requests
(
doc
,
txt
)
# todo: mock lm by pluggin what's currently in main.py in here
for
req
in
reqs
:
assert
isinstance
(
req
,
base
.
Request
)
\ No newline at end of file
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