Skip to content

Commit

Permalink
endret til å bruke vanlige funksjoner i stedet for lambdaer
Browse files Browse the repository at this point in the history
  • Loading branch information
kvalle committed Apr 12, 2012
1 parent fa91131 commit 4033e1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ Remove leading and trailing whitespace from strings.
If you complete the task quickly, try one or more of the following:

- Add descriptions to each URL in the `urls.txt` file, and use these when creating the `Test` objects.
- Instead of wrapping `HTTPRequest` with the tests like we did in task 1, try wrapping a [lambda](http://docs.python.org/tutorial/controlflow.html#lambda-forms) that does all the work (e.g. create a HTTPRequest and call `GET` with the correct URL).
This way, you won't need to keep track of *both* test objects and their URLs in the `__call__` method.
- Instead of wrapping `HTTPRequest` with the tests like we did in task 1, try creating functions to do all the work (e.g. create a HTTPRequest and call `GET` with the correct URL), and then wrap these with your tests.
This way, you won't need to keep track of URLs in addition to the tests in the `__call__` method.


## Task 3 - Validating the responses
Expand Down
10 changes: 7 additions & 3 deletions solutions/scripts/task2-extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
url_file_path = grinder.getProperties().getProperty('task2.urls')

def request_factory(url):
return lambda: HTTPRequest().GET(url)
def send_request():
request = HTTPRequest()
request.GET(url)
return send_request

class TestRunner:

Expand All @@ -15,8 +18,9 @@ def __init__(self):
for num, line in enumerate(url_file):
url, description = line.split(' ', 1)
test = Test(num, description.strip())
request = test.wrap(request_factory(url))
self.requests.append(request)
request_fn = request_factory(url)
wrapped_request_fn = test.wrap(request_fn)
self.requests.append(wrapped_request_fn)
url_file.close()

def __call__(self):
Expand Down

0 comments on commit 4033e1b

Please sign in to comment.