Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flamenco-worker-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
flamenco-worker-python
Commits
3d121eee
Commit
3d121eee
authored
8 years ago
by
Sybren A. Stüvel
Browse files
Options
Downloads
Patches
Plain Diff
Removed CoroMock, when it fails it's really cryptic what's going on.
parent
171abbc1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_may_i_run.py
+22
-10
22 additions, 10 deletions
tests/test_may_i_run.py
with
22 additions
and
10 deletions
tests/test_may_i_run.py
+
22
−
10
View file @
3d121eee
import
typing
from
unittest.mock
import
Mock
from
abstract_worker_test
import
AbstractWorkerTest
...
...
@@ -7,7 +9,6 @@ class MayIRunTest(AbstractWorkerTest):
def
setUp
(
self
):
from
datetime
import
timedelta
from
mock_responses
import
CoroMock
from
flamenco_worker.may_i_run
import
MayIRun
from
flamenco_worker.upstream
import
FlamencoManager
from
flamenco_worker.worker
import
FlamencoWorker
...
...
@@ -15,7 +16,7 @@ class MayIRunTest(AbstractWorkerTest):
self
.
loop
=
construct_asyncio_loop
()
self
.
manager
=
Mock
(
spec
=
FlamencoManager
)
self
.
manager
.
get
=
Coro
Mock
()
self
.
manager
.
get
=
Mock
()
self
.
worker
=
Mock
(
spec
=
FlamencoWorker
)
self
.
shutdown_future
=
self
.
loop
.
create_future
()
...
...
@@ -24,19 +25,30 @@ class MayIRunTest(AbstractWorkerTest):
poll_interval
=
timedelta
(
seconds
=
0.2
),
loop
=
self
.
loop
)
def
_mock_get
(
self
,
*
json_responses
:
dict
):
import
collections
values
=
collections
.
deque
(
json_responses
)
async
def
mocked_get
(
*
args
,
**
kwargs
):
mock_resp
=
Mock
()
mock_resp
.
json
.
return_value
=
values
.
popleft
()
return
mock_resp
self
.
manager
.
get
=
mocked_get
def
test_may_i_run_false
(
self
):
self
.
manager
.
get
.
coro
.
return_value
.
json
.
return_value
=
{
'
may_keep_running
'
:
False
,
'
reason
'
:
'
je moeder
'
,
}
self
.
_mock_get
(
{
'
may_keep_running
'
:
False
,
'
reason
'
:
'
je moeder
'
,
})
result
=
self
.
loop
.
run_until_complete
(
self
.
mir
.
may_i_run
(
'
1234
'
))
self
.
assertFalse
(
result
)
def
test_may_i_run_true
(
self
):
self
.
manager
.
get
.
coro
.
return_value
.
json
.
return_value
=
{
self
.
_mock_get
(
{
'
may_keep_running
'
:
True
,
}
}
)
result
=
self
.
loop
.
run_until_complete
(
self
.
mir
.
may_i_run
(
'
1234
'
))
self
.
assertTrue
(
result
)
...
...
@@ -44,11 +56,11 @@ class MayIRunTest(AbstractWorkerTest):
def
test_work
(
self
):
import
asyncio
self
.
manager
.
get
.
coro
.
return_value
.
json
.
side_effect
=
[
self
.
_mock_get
(
{
'
may_keep_running
'
:
True
},
{
'
may_keep_running
'
:
False
,
'
reason
'
:
'
unittesting
'
},
# After this response, no more calls should be made.
]
)
# Let the 'stop_current_task()' call trigger an event.
stop_event
=
asyncio
.
Event
()
...
...
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