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
515d5b7d
Commit
515d5b7d
authored
8 years ago
by
Sybren A. Stüvel
Browse files
Options
Downloads
Patches
Plain Diff
Fixed some test issues with CoroMock()
parent
3d121eee
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/mock_responses.py
+5
-1
5 additions, 1 deletion
tests/mock_responses.py
tests/test_may_i_run.py
+10
-12
10 additions, 12 deletions
tests/test_may_i_run.py
tests/test_runner_blender_render.py
+1
-1
1 addition, 1 deletion
tests/test_runner_blender_render.py
with
16 additions
and
14 deletions
tests/mock_responses.py
+
5
−
1
View file @
515d5b7d
...
@@ -37,12 +37,16 @@ class EmptyResponse:
...
@@ -37,12 +37,16 @@ class EmptyResponse:
pass
pass
def
CoroMock
(
return_value
=
...
):
def
CoroMock
(
return_value
=
None
):
"""
Corountine mocking object.
"""
Corountine mocking object.
For an example, see test_coro_mock.py.
For an example, see test_coro_mock.py.
Source: http://stackoverflow.com/a/32505333/875379
Source: http://stackoverflow.com/a/32505333/875379
:param return_value: whatever you want to have set as return value.
This must always be set. Pass the ellipsis object ... to not set this; in that case
you are responsible yourself to set coromock.coro.return_value.
"""
"""
import
asyncio
import
asyncio
...
...
This diff is collapsed.
Click to expand it.
tests/test_may_i_run.py
+
10
−
12
View file @
515d5b7d
import
typing
from
unittest.mock
import
Mock
from
unittest.mock
import
Mock
from
abstract_worker_test
import
AbstractWorkerTest
from
abstract_worker_test
import
AbstractWorkerTest
...
@@ -16,7 +14,6 @@ class MayIRunTest(AbstractWorkerTest):
...
@@ -16,7 +14,6 @@ class MayIRunTest(AbstractWorkerTest):
self
.
loop
=
construct_asyncio_loop
()
self
.
loop
=
construct_asyncio_loop
()
self
.
manager
=
Mock
(
spec
=
FlamencoManager
)
self
.
manager
=
Mock
(
spec
=
FlamencoManager
)
self
.
manager
.
get
=
Mock
()
self
.
worker
=
Mock
(
spec
=
FlamencoWorker
)
self
.
worker
=
Mock
(
spec
=
FlamencoWorker
)
self
.
shutdown_future
=
self
.
loop
.
create_future
()
self
.
shutdown_future
=
self
.
loop
.
create_future
()
...
@@ -25,22 +22,23 @@ class MayIRunTest(AbstractWorkerTest):
...
@@ -25,22 +22,23 @@ class MayIRunTest(AbstractWorkerTest):
poll_interval
=
timedelta
(
seconds
=
0.2
),
poll_interval
=
timedelta
(
seconds
=
0.2
),
loop
=
self
.
loop
)
loop
=
self
.
loop
)
def
_mock_get
(
self
,
*
json_responses
:
dict
):
def
_mock_get
(
self
,
*
json_responses
):
import
collections
from
collections
import
deque
values
=
collections
.
deque
(
json_responses
)
values
=
deque
(
json_responses
)
async
def
mocked_get
(
*
args
,
**
kwargs
):
async
def
mocked_get
(
*
args
,
**
kwargs
):
mock_resp
=
Mock
()
mock
ed
_resp
onse
=
Mock
()
mock_resp
.
json
.
return_value
=
values
.
popleft
()
mock
ed
_resp
onse
.
json
.
return_value
=
values
.
popleft
()
return
mock_resp
return
mock
ed
_resp
onse
self
.
manager
.
get
=
mocked_get
self
.
manager
.
get
=
mocked_get
def
test_may_i_run_false
(
self
):
def
test_may_i_run_false
(
self
):
self
.
_mock_get
({
self
.
_mock_get
({
'
may_keep_running
'
:
False
,
'
may_keep_running
'
:
False
,
'
reason
'
:
'
je moeder
'
,
'
reason
'
:
'
je moeder
'
,
})
})
result
=
self
.
loop
.
run_until_complete
(
self
.
mir
.
may_i_run
(
'
1234
'
))
result
=
self
.
loop
.
run_until_complete
(
self
.
mir
.
may_i_run
(
'
1234
'
))
self
.
assertFalse
(
result
)
self
.
assertFalse
(
result
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_runner_blender_render.py
+
1
−
1
View file @
515d5b7d
...
@@ -81,7 +81,7 @@ class BlenderRenderTest(AbstractCommandTest):
...
@@ -81,7 +81,7 @@ class BlenderRenderTest(AbstractCommandTest):
'
filepath
'
:
filepath
,
'
filepath
'
:
filepath
,
}
}
cse
=
CoroMock
()
cse
=
CoroMock
(
...
)
cse
.
coro
.
return_value
.
wait
=
CoroMock
(
return_value
=
0
)
cse
.
coro
.
return_value
.
wait
=
CoroMock
(
return_value
=
0
)
with
patch
(
'
asyncio.create_subprocess_exec
'
,
new
=
cse
)
as
mock_cse
:
with
patch
(
'
asyncio.create_subprocess_exec
'
,
new
=
cse
)
as
mock_cse
:
self
.
loop
.
run_until_complete
(
self
.
cmd
.
run
(
settings
))
self
.
loop
.
run_until_complete
(
self
.
cmd
.
run
(
settings
))
...
...
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