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
14a194e5
Commit
14a194e5
authored
Jan 21, 2014
by
Ricky Cook
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move in_directory decorator to FileSystem class
parent
c8d43f80
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
58 additions
and
64 deletions
+58
-64
lettuce/fs.py
+18
-0
tests/integration/test_alfaces.py
+15
-16
tests/integration/test_bamboo.py
+3
-3
tests/integration/test_brocolis.py
+5
-5
tests/integration/test_celeries.py
+2
-2
tests/integration/test_chive.py
+1
-2
tests/integration/test_couves.py
+3
-3
tests/integration/test_cucumber.py
+2
-2
tests/integration/test_dill.py
+4
-4
tests/integration/test_grocery.py
+3
-4
tests/integration/test_kale.py
+2
-2
tests/util.py
+0
-21
No files found.
lettuce/fs.py
View file @
14a194e5
...
...
@@ -22,6 +22,7 @@ import codecs
import
fnmatch
import
zipfile
from
functools
import
wraps
from
glob
import
glob
from
os.path
import
abspath
,
join
,
dirname
,
curdir
,
exists
...
...
@@ -241,3 +242,20 @@ class FileSystem(object):
path
=
cls
.
current_dir
(
name
)
return
open
(
path
,
mode
)
@classmethod
def
in_directory
(
cls
,
*
directories
):
"""Decorator to set the working directory around a function"""
def
decorator
(
func
):
@wraps
(
func
)
def
inner
(
*
args
,
**
kwargs
):
cls
.
pushd
(
*
directories
)
try
:
return
func
(
*
args
,
**
kwargs
)
finally
:
cls
.
popd
()
return
inner
return
decorator
tests/integration/test_alfaces.py
View file @
14a194e5
...
...
@@ -20,12 +20,11 @@ import commands
import
multiprocessing
from
tests.asserts
import
assert_equals
,
assert_not_equals
from
tests.util
import
in_directory
from
lettuce.fs
import
FileSystem
current_directory
=
FileSystem
.
dirname
(
__file__
)
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_django_agains_alfaces
():
'running the "harvest" django command with verbosity 3'
...
...
@@ -37,7 +36,7 @@ def test_django_agains_alfaces():
assert
"Test the django app FOO BAR"
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_django_background_server_running_in_background
():
'the django builtin server fails if the HTTP port is not available'
...
...
@@ -76,7 +75,7 @@ def test_django_background_server_running_in_background():
os
.
kill
(
server
.
pid
,
9
)
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_django_background_server_running_in_background_with_custom_port
():
'the harvest command should take a --port argument'
...
...
@@ -115,7 +114,7 @@ def test_django_background_server_running_in_background_with_custom_port():
os
.
kill
(
server
.
pid
,
9
)
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_limit_by_app_getting_all_apps_by_comma
():
'running "harvest" with --apps=multiple,apps,separated,by,comma'
...
...
@@ -127,7 +126,7 @@ def test_limit_by_app_getting_all_apps_by_comma():
assert
"Test the django app FOO BAR"
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_limit_by_app_getting_one_app
():
'running "harvest" with --apps=one_app'
...
...
@@ -139,7 +138,7 @@ def test_limit_by_app_getting_one_app():
assert
"Test the django app FOO BAR"
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_excluding_apps_separated_by_comma
():
'running "harvest" with --avoid-apps=multiple,apps'
...
...
@@ -151,7 +150,7 @@ def test_excluding_apps_separated_by_comma():
assert
"Test the django app FOO BAR"
not
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_excluding_app
():
'running "harvest" with --avoid-apps=one_app'
...
...
@@ -163,7 +162,7 @@ def test_excluding_app():
assert
"Test the django app FOO BAR"
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_running_only_apps_within_lettuce_apps_setting
():
'running the "harvest" will run only on configured apps if the '
\
'setting LETTUCE_APPS is set'
...
...
@@ -176,7 +175,7 @@ def test_running_only_apps_within_lettuce_apps_setting():
assert
"Test the django app DO NOTHING"
not
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_running_all_apps_but_lettuce_avoid_apps
():
'running the "harvest" will run all apps but those within '
\
'LETTUCE_AVOID_APPS'
...
...
@@ -191,7 +190,7 @@ def test_running_all_apps_but_lettuce_avoid_apps():
assert
"Test the django app DO NOTHING"
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_ignores_settings_avoid_apps_if_apps_argument_is_passed
():
'even if all apps are avoid in settings, it is possible to run a single '
\
'app by --apps argument'
...
...
@@ -205,7 +204,7 @@ def test_ignores_settings_avoid_apps_if_apps_argument_is_passed():
assert
"Test the django app DO NOTHING"
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_no_server
():
'"harvest" --no-server does not start the server'
...
...
@@ -216,7 +215,7 @@ def test_no_server():
assert
"Django's builtin server is running at"
not
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_django_specifying_scenarios_to_run
():
'django harvest can run only specified scenarios with '
\
'--scenarios or -s options'
...
...
@@ -234,7 +233,7 @@ def test_django_specifying_scenarios_to_run():
assert
"6th scenario"
not
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_django_specifying_scenarios_to_run_by_tag
():
'django harvest can run only specified scenarios with '
\
'--tags or -t options'
...
...
@@ -252,7 +251,7 @@ def test_django_specifying_scenarios_to_run_by_tag():
assert
"5th scenario"
not
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_running_only_specified_features
():
'it can run only the specified features, passing the file path'
...
...
@@ -266,7 +265,7 @@ def test_running_only_specified_features():
assert
"Test the django app DO NOTHING"
not
in
out
@in_directory
(
current_directory
,
'django'
,
'alfaces'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'alfaces'
)
def
test_specifying_features_in_inner_directory
():
'it can run only the specified features from a subdirectory'
...
...
tests/integration/test_bamboo.py
View file @
14a194e5
...
...
@@ -16,12 +16,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
lettuce.fs
import
FileSystem
from
nose.tools
import
assert_equals
,
assert_not_equals
from
tests.util
import
in_directory
,
run_scenario
from
tests.util
import
run_scenario
current_directory
=
FileSystem
.
dirname
(
__file__
)
@in_directory
(
current_directory
,
'django'
,
'bamboo'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'bamboo'
)
def
test_mail_count
():
'Mail count is checked through Lettuce steps'
...
...
@@ -35,7 +35,7 @@ def test_mail_count():
assert
"Length of outbox is 1"
in
out
@in_directory
(
current_directory
,
'django'
,
'bamboo'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'bamboo'
)
def
test_mail_content
():
'Mail content is checked through Lettuce steps'
...
...
tests/integration/test_brocolis.py
View file @
14a194e5
...
...
@@ -17,12 +17,12 @@
import
commands
from
lettuce.fs
import
FileSystem
from
nose.tools
import
assert_equals
from
tests.util
import
in_directory
,
run_scenario
from
tests.util
import
run_scenario
current_directory
=
FileSystem
.
dirname
(
__file__
)
@in_directory
(
current_directory
,
'django'
,
'brocolis'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'brocolis'
)
def
test_harvest_with_debug_mode_enabled
():
'python manage.py harvest -d turns settings.DEBUG=True'
...
...
@@ -31,7 +31,7 @@ def test_harvest_with_debug_mode_enabled():
assert_equals
(
status
,
0
,
out
)
@in_directory
(
current_directory
,
'django'
,
'brocolis'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'brocolis'
)
def
test_harvest_with_debug_mode_disabled
():
'python manage.py harvest without turns settings.DEBUG=False'
...
...
@@ -39,7 +39,7 @@ def test_harvest_with_debug_mode_disabled():
assert_equals
(
status
,
0
,
out
)
@in_directory
(
current_directory
,
'django'
,
'brocolis'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'brocolis'
)
def
test_harvest_sets_environment_variabled_for_gae
():
'harvest sets environment variables SERVER_NAME and SERVER_PORT in order to work with google app engine'
...
...
@@ -47,7 +47,7 @@ def test_harvest_sets_environment_variabled_for_gae():
assert_equals
(
status
,
0
,
out
)
@in_directory
(
current_directory
,
'django'
,
'brocolis'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'brocolis'
)
def
test_harvest_uses_test_runner
():
'harvest uses TEST_RUNNER specified in settings'
...
...
tests/integration/test_celeries.py
View file @
14a194e5
...
...
@@ -17,12 +17,12 @@
import
commands
from
lettuce.fs
import
FileSystem
from
sure
import
this
as
the
from
tests.util
import
in_directory
,
run_scenario
from
tests.util
import
run_scenario
current_directory
=
FileSystem
.
dirname
(
__file__
)
@in_directory
(
current_directory
,
'django'
,
'celeries'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'celeries'
)
def
test_failfast
():
'passing --failfast to the harvest command will cause lettuce to stop in the first failure'
...
...
tests/integration/test_chive.py
View file @
14a194e5
...
...
@@ -20,7 +20,6 @@ import commands
from
lettuce.fs
import
FileSystem
from
tests.asserts
import
assert_not_equals
from
tests.util
import
in_directory
current_directory
=
FileSystem
.
dirname
(
__file__
)
lib_directory
=
FileSystem
.
join
(
current_directory
,
'lib'
)
...
...
@@ -33,7 +32,7 @@ def teardown():
os
.
environ
[
'PYTHONPATH'
]
=
OLD_PYTHONPATH
@in_directory
(
current_directory
,
'django'
,
'chive'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'chive'
)
def
test_django_admin_media_serving_on_django_13
():
'lettuce should serve admin static files properly on Django 1.3'
...
...
tests/integration/test_couves.py
View file @
14a194e5
...
...
@@ -17,12 +17,12 @@
import
commands
from
lettuce.fs
import
FileSystem
from
sure
import
expect
from
tests.util
import
in_directory
,
run_scenario
from
tests.util
import
run_scenario
current_directory
=
FileSystem
.
dirname
(
__file__
)
@in_directory
(
current_directory
,
'django'
,
'couves'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'couves'
)
def
test_django_agains_couves
():
'it always call @after.all hooks, even after exceptions'
...
...
@@ -32,7 +32,7 @@ def test_django_agains_couves():
expect
(
"Couves after all"
)
.
to
.
be
.
within
(
out
)
@in_directory
(
current_directory
,
'django'
,
'couves'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'couves'
)
def
test_django_agains_couves_nohooks
():
'it only calls @before.all and @after.all hooks if there are features found'
...
...
tests/integration/test_cucumber.py
View file @
14a194e5
...
...
@@ -17,12 +17,12 @@
import
commands
from
lettuce.fs
import
FileSystem
from
tests.util
import
in_directory
,
run_scenario
from
tests.util
import
run_scenario
current_directory
=
FileSystem
.
dirname
(
__file__
)
@in_directory
(
current_directory
,
'django'
,
'cucumber'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'cucumber'
)
def
test_django_against_cucumber_django_project
():
'testing all django hooks'
...
...
tests/integration/test_dill.py
View file @
14a194e5
...
...
@@ -17,12 +17,12 @@
import
commands
from
lettuce.fs
import
FileSystem
from
nose.tools
import
assert_equals
,
assert_not_equals
from
tests.util
import
in_directory
,
run_scenario
from
tests.util
import
run_scenario
current_directory
=
FileSystem
.
dirname
(
__file__
)
@in_directory
(
current_directory
,
'django'
,
'dill'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'dill'
)
def
test_model_creation
():
'Models are created through Lettuce steps'
...
...
@@ -30,7 +30,7 @@ def test_model_creation():
assert_equals
(
status
,
0
,
out
)
@in_directory
(
current_directory
,
'django'
,
'dill'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'dill'
)
def
test_model_existence_check
():
'Model existence is checked through Lettuce steps'
...
...
@@ -67,7 +67,7 @@ def test_model_existence_check():
assert
"Expected 2 geese, found 1"
in
out
@in_directory
(
current_directory
,
'django'
,
'dill'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'dill'
)
def
test_use_test_database_setting
():
'Test database is recreated each time if LETTUCE_USE_TEST_DATABASE is set'
...
...
tests/integration/test_grocery.py
View file @
14a194e5
...
...
@@ -20,7 +20,6 @@ import commands
from
lettuce.fs
import
FileSystem
from
tests.asserts
import
assert_equals
from
tests.util
import
in_directory
current_directory
=
FileSystem
.
dirname
(
__file__
)
lib_directory
=
FileSystem
.
join
(
current_directory
,
'lib'
)
...
...
@@ -33,7 +32,7 @@ def teardown():
os
.
environ
[
'PYTHONPATH'
]
=
OLD_PYTHONPATH
@in_directory
(
current_directory
,
'django'
,
'grocery'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'grocery'
)
def
test_django_admin_media_serving_on_django_13
():
'lettuce should serve admin static files properly on Django 1.3'
...
...
@@ -58,7 +57,7 @@ def test_django_admin_media_serving_on_django_13():
assert
u"Django's builtin server is running at 0.0.0.0:7000"
in
lines
@in_directory
(
current_directory
,
'django'
,
'grocery'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'grocery'
)
def
test_django_admin_media_serving_on_django_125
():
'lettuce should serve admin static files properly on Django 1.2.5'
...
...
@@ -86,7 +85,7 @@ def test_django_admin_media_serving_on_django_125():
assert
u'Fetching javascript files: ... OK'
in
lines
,
f
@in_directory
(
current_directory
,
'django'
,
'grocery'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'grocery'
)
def
test_django_admin_media_serving_forced_by_setting
():
'settings.LETTUCE_SERVE_ADMIN_MEDIA forces lettuce to serve admin assets'
...
...
tests/integration/test_kale.py
View file @
14a194e5
...
...
@@ -17,12 +17,12 @@
import
commands
from
lettuce.fs
import
FileSystem
from
nose.tools
import
assert_equals
from
tests.util
import
in_directory
,
run_scenario
from
tests.util
import
run_scenario
current_directory
=
FileSystem
.
dirname
(
__file__
)
@in_directory
(
current_directory
,
'django'
,
'kale'
)
@
FileSystem.
in_directory
(
current_directory
,
'django'
,
'kale'
)
def
test_harvest_uses_test_runner
():
'harvest uses LETTUCE_TEST_SERVER specified in settings'
...
...
tests/util.py
View file @
14a194e5
...
...
@@ -2,8 +2,6 @@
Utils for testing
"""
import
commands
from
functools
import
wraps
from
lettuce.fs
import
FileSystem
def
run_scenario
(
application
=
''
,
feature
=
''
,
scenario
=
''
,
**
opts
):
...
...
@@ -32,22 +30,3 @@ def run_scenario(application='', feature='', scenario='', **opts):
scenario
,
)
return
commands
.
getstatusoutput
(
cmd
)
def
in_directory
(
*
directories
):
"""
Decorator to set the working directory around a function
"""
def
decorator
(
func
):
@wraps
(
func
)
def
inner
(
*
args
,
**
kwargs
):
FileSystem
.
pushd
(
*
directories
)
try
:
return
func
(
*
args
,
**
kwargs
)
finally
:
FileSystem
.
popd
()
return
inner
return
decorator
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