Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lettuce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
lettuce
Commits
70d06603
Commit
70d06603
authored
Sep 22, 2013
by
Grégory Salvan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure callable are functions or methods for load_steps
parent
27e0db17
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
2 deletions
+20
-2
lettuce/registry.py
+6
-1
tests/unit/test_registry.py
+14
-1
No files found.
lettuce/registry.py
View file @
70d06603
...
@@ -59,6 +59,7 @@ class StepDict(dict):
...
@@ -59,6 +59,7 @@ class StepDict(dict):
return
obj
return
obj
def
_extract_sentence
(
self
,
func
):
def
_extract_sentence
(
self
,
func
):
func
=
getattr
(
func
,
'__func__'
,
func
)
sentence
=
getattr
(
func
,
'__doc__'
,
None
)
sentence
=
getattr
(
func
,
'__doc__'
,
None
)
if
sentence
is
None
:
if
sentence
is
None
:
sentence
=
func
.
func_name
.
replace
(
'_'
,
' '
)
sentence
=
func
.
func_name
.
replace
(
'_'
,
' '
)
...
@@ -75,7 +76,11 @@ class StepDict(dict):
...
@@ -75,7 +76,11 @@ class StepDict(dict):
" error:
%
s"
%
(
step
,
func
,
e
))
" error:
%
s"
%
(
step
,
func
,
e
))
def
_attr_is_step
(
self
,
attr
,
obj
):
def
_attr_is_step
(
self
,
attr
,
obj
):
return
attr
[
0
]
!=
'_'
and
callable
(
getattr
(
obj
,
attr
))
return
attr
[
0
]
!=
'_'
and
self
.
_is_func_or_method
(
getattr
(
obj
,
attr
))
def
_is_func_or_method
(
self
,
func
):
func_dir
=
dir
(
func
)
return
callable
(
func
)
and
(
"func_name"
in
func_dir
or
"__func__"
in
func_dir
)
STEP_REGISTRY
=
StepDict
()
STEP_REGISTRY
=
StepDict
()
...
...
tests/unit/test_registry.py
View file @
70d06603
...
@@ -105,7 +105,7 @@ def test_StepDict_can_load_steps_from_an_object():
...
@@ -105,7 +105,7 @@ def test_StepDict_can_load_steps_from_an_object():
assert_equal
(
steps
[
expected_sentence2
],
step_list
.
step_2
)
assert_equal
(
steps
[
expected_sentence2
],
step_list
.
step_2
)
def
test_StepDict_can_exclude_methods_when_load_steps
():
def
test_StepDict_can_exclude_methods_when_load_steps
():
u"lettuce.STEP_REGISTRY.load_steps(obj)
append all obj methods to STEP_REGISTRY except ones in attr 'exclude'
"
u"lettuce.STEP_REGISTRY.load_steps(obj)
don't load exluded attr in STEP_REGISTRY
"
steps
=
StepDict
()
steps
=
StepDict
()
class
LotsOfSteps
:
class
LotsOfSteps
:
exclude
=
[
"step_1"
]
exclude
=
[
"step_1"
]
...
@@ -122,3 +122,16 @@ def test_StepDict_can_exclude_methods_when_load_steps():
...
@@ -122,3 +122,16 @@ def test_StepDict_can_exclude_methods_when_load_steps():
expected_sentence2
=
"Doing something"
expected_sentence2
=
"Doing something"
assert
(
expected_sentence1
not
in
steps
)
assert
(
expected_sentence1
not
in
steps
)
assert
(
expected_sentence2
in
steps
)
assert
(
expected_sentence2
in
steps
)
def
test_StepDict_can_exclude_callable_object_when_load_steps
():
u"lettuce.STEP_REGISTRY.load_steps(obj) don't load callable objets in STEP_REGISTRY"
steps
=
StepDict
()
class
NoStep
:
class
NotAStep
(
object
):
def
__call__
(
self
):
pass
no_step
=
NoStep
()
steps
.
load_steps
(
no_step
)
assert
len
(
steps
)
==
0
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