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
OpenDAS
Fairseq
Commits
0b5166db
Commit
0b5166db
authored
Jul 31, 2018
by
alexeib
Committed by
Myle Ott
Sep 03, 2018
Browse files
fix tests
parent
2dc074d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
tests/test_train.py
tests/test_train.py
+6
-3
No files found.
tests/test_train.py
View file @
0b5166db
...
@@ -52,6 +52,8 @@ def get_trainer_and_epoch_itr(epoch, epoch_size, num_updates, iterations_in_epoc
...
@@ -52,6 +52,8 @@ def get_trainer_and_epoch_itr(epoch, epoch_size, num_updates, iterations_in_epoc
class
TestLoadCheckpoint
(
unittest
.
TestCase
):
class
TestLoadCheckpoint
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
args_mock
=
MagicMock
()
self
.
args_mock
.
optimizer_overrides
=
'{}'
self
.
patches
=
{
self
.
patches
=
{
'os.makedirs'
:
MagicMock
(),
'os.makedirs'
:
MagicMock
(),
'os.path.join'
:
MagicMock
(),
'os.path.join'
:
MagicMock
(),
...
@@ -60,11 +62,12 @@ class TestLoadCheckpoint(unittest.TestCase):
...
@@ -60,11 +62,12 @@ class TestLoadCheckpoint(unittest.TestCase):
self
.
applied_patches
=
[
patch
(
p
,
d
)
for
p
,
d
in
self
.
patches
.
items
()]
self
.
applied_patches
=
[
patch
(
p
,
d
)
for
p
,
d
in
self
.
patches
.
items
()]
[
p
.
start
()
for
p
in
self
.
applied_patches
]
[
p
.
start
()
for
p
in
self
.
applied_patches
]
def
test_load_partial_checkpoint
(
self
):
def
test_load_partial_checkpoint
(
self
):
with
contextlib
.
redirect_stdout
(
StringIO
()):
with
contextlib
.
redirect_stdout
(
StringIO
()):
trainer
,
epoch_itr
=
get_trainer_and_epoch_itr
(
2
,
150
,
200
,
50
)
trainer
,
epoch_itr
=
get_trainer_and_epoch_itr
(
2
,
150
,
200
,
50
)
train
.
load_checkpoint
(
MagicM
ock
()
,
trainer
,
epoch_itr
)
train
.
load_checkpoint
(
self
.
args_m
ock
,
trainer
,
epoch_itr
)
self
.
assertEqual
(
epoch_itr
.
epoch
,
2
)
self
.
assertEqual
(
epoch_itr
.
epoch
,
2
)
self
.
assertEqual
(
epoch_itr
.
iterations_in_epoch
,
50
)
self
.
assertEqual
(
epoch_itr
.
iterations_in_epoch
,
50
)
...
@@ -79,7 +82,7 @@ class TestLoadCheckpoint(unittest.TestCase):
...
@@ -79,7 +82,7 @@ class TestLoadCheckpoint(unittest.TestCase):
with
contextlib
.
redirect_stdout
(
StringIO
()):
with
contextlib
.
redirect_stdout
(
StringIO
()):
trainer
,
epoch_itr
=
get_trainer_and_epoch_itr
(
2
,
150
,
300
,
150
)
trainer
,
epoch_itr
=
get_trainer_and_epoch_itr
(
2
,
150
,
300
,
150
)
train
.
load_checkpoint
(
MagicM
ock
()
,
trainer
,
epoch_itr
)
train
.
load_checkpoint
(
self
.
args_m
ock
,
trainer
,
epoch_itr
)
itr
=
epoch_itr
.
next_epoch_itr
(
shuffle
=
False
)
itr
=
epoch_itr
.
next_epoch_itr
(
shuffle
=
False
)
self
.
assertEqual
(
epoch_itr
.
epoch
,
3
)
self
.
assertEqual
(
epoch_itr
.
epoch
,
3
)
...
@@ -91,7 +94,7 @@ class TestLoadCheckpoint(unittest.TestCase):
...
@@ -91,7 +94,7 @@ class TestLoadCheckpoint(unittest.TestCase):
trainer
,
epoch_itr
=
get_trainer_and_epoch_itr
(
0
,
150
,
0
,
0
)
trainer
,
epoch_itr
=
get_trainer_and_epoch_itr
(
0
,
150
,
0
,
0
)
self
.
patches
[
'os.path.isfile'
].
return_value
=
False
self
.
patches
[
'os.path.isfile'
].
return_value
=
False
train
.
load_checkpoint
(
MagicM
ock
()
,
trainer
,
epoch_itr
)
train
.
load_checkpoint
(
self
.
args_m
ock
,
trainer
,
epoch_itr
)
itr
=
epoch_itr
.
next_epoch_itr
(
shuffle
=
False
)
itr
=
epoch_itr
.
next_epoch_itr
(
shuffle
=
False
)
self
.
assertEqual
(
epoch_itr
.
epoch
,
1
)
self
.
assertEqual
(
epoch_itr
.
epoch
,
1
)
...
...
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