assert_raises() from nose.tools won't work rightHow to use nose's assert_raises?How to randomly select an item from a list?How do I remove an element from a list by index in Python?How do you read from stdin?Why can't Python parse this JSON data?Why is reading lines from stdin much slower in C++ than Python?How to remove a key from a Python dictionary?Scipy autotest finished with one errorsomething errors were thrown out when I was testing the scikit-learn with nosetestsHow to use a python function from another moduleSkeleton Directory: Why does script fail when nosetests returns no errors?
Taxes on Dividends in a Roth IRA
I found an audio circuit and I built it just fine, but I find it a bit too quiet. How do I amplify the output so that it is a bit louder?
Review your own paper in Mathematics
Does "he squandered his car on drink" sound natural?
Change the color of a single dot in `ddot` symbol
Creating two special characters
How can ping know if my host is down
Delete multiple columns using awk or sed
Mimic lecturing on blackboard, facing audience
How to explain what's wrong with this application of the chain rule?
What (the heck) is a Super Worm Equinox Moon?
What does Apple's new App Store requirement mean
Shouldn’t conservatives embrace universal basic income?
How much theory knowledge is actually used while playing?
Multiplicative persistence
Is this toilet slogan correct usage of the English language?
Why Shazam when there is already Superman?
Why do Radio Buttons not fill the entire outer circle?
It grows, but water kills it
Why is so much work done on numerical verification of the Riemann Hypothesis?
Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?
What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?
Why do ¬, ∀ and ∃ have the same precedence?
Were Persian-Median kings illiterate?
assert_raises() from nose.tools won't work right
How to use nose's assert_raises?How to randomly select an item from a list?How do I remove an element from a list by index in Python?How do you read from stdin?Why can't Python parse this JSON data?Why is reading lines from stdin much slower in C++ than Python?How to remove a key from a Python dictionary?Scipy autotest finished with one errorsomething errors were thrown out when I was testing the scikit-learn with nosetestsHow to use a python function from another moduleSkeleton Directory: Why does script fail when nosetests returns no errors?
I'm halfway through the book Learn Python the Hard Way by Zed Shaw. The book doesn't have any coverage or documentation for the function assert_raises()
.
So I tried to run this test:
from nose.tools import *
from ex48.parser import *
def test_except():
raw_sentence = [('stop', 'the'), ('noun', 'bear'), ('verb', 'kill')]
assert_raises(ParserError, parse_sentence(raw_sentence))
Here's the error when I tried to run nosetests
:
======================================================================
ERROR: tests.parser_tests.test_except
----------------------------------------------------------------------
Traceback (most recent call last):
File "####/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "####/ex48/tests/parser_tests.py", line 8, in test_except
assert_raises(ParserError, parse_sentence(raw_sentence))
File "####/ex48/ex48/parser.py", line 69, in parse_sentence
obj = parse_object(word_list)
File "####/ex48/ex48/parser.py", line 53, in parse_object
raise ParserError("Expected a noun or direction next.")
ParserError: Expected a noun or direction next.
----------------------------------------------------------------------
Ran 8 tests in 0.008s
FAILED (errors=1)
Here is where the exception is coming from:
def parse_verb(word_list):
skip(word_list, 'stop')
if peek(word_list) == 'verb':
return match(word_list, 'verb')
else:
raise ParserError("Expected a verb next.")
The call to parse_sentence(raw_sentence)
is expected to fail. The assert_raises()
should work properly, but it doesn't catch the raised exception from parse_verb()
yielding a failed test. What do you think is/are the problem/s?
python python-2.7
add a comment |
I'm halfway through the book Learn Python the Hard Way by Zed Shaw. The book doesn't have any coverage or documentation for the function assert_raises()
.
So I tried to run this test:
from nose.tools import *
from ex48.parser import *
def test_except():
raw_sentence = [('stop', 'the'), ('noun', 'bear'), ('verb', 'kill')]
assert_raises(ParserError, parse_sentence(raw_sentence))
Here's the error when I tried to run nosetests
:
======================================================================
ERROR: tests.parser_tests.test_except
----------------------------------------------------------------------
Traceback (most recent call last):
File "####/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "####/ex48/tests/parser_tests.py", line 8, in test_except
assert_raises(ParserError, parse_sentence(raw_sentence))
File "####/ex48/ex48/parser.py", line 69, in parse_sentence
obj = parse_object(word_list)
File "####/ex48/ex48/parser.py", line 53, in parse_object
raise ParserError("Expected a noun or direction next.")
ParserError: Expected a noun or direction next.
----------------------------------------------------------------------
Ran 8 tests in 0.008s
FAILED (errors=1)
Here is where the exception is coming from:
def parse_verb(word_list):
skip(word_list, 'stop')
if peek(word_list) == 'verb':
return match(word_list, 'verb')
else:
raise ParserError("Expected a verb next.")
The call to parse_sentence(raw_sentence)
is expected to fail. The assert_raises()
should work properly, but it doesn't catch the raised exception from parse_verb()
yielding a failed test. What do you think is/are the problem/s?
python python-2.7
add a comment |
I'm halfway through the book Learn Python the Hard Way by Zed Shaw. The book doesn't have any coverage or documentation for the function assert_raises()
.
So I tried to run this test:
from nose.tools import *
from ex48.parser import *
def test_except():
raw_sentence = [('stop', 'the'), ('noun', 'bear'), ('verb', 'kill')]
assert_raises(ParserError, parse_sentence(raw_sentence))
Here's the error when I tried to run nosetests
:
======================================================================
ERROR: tests.parser_tests.test_except
----------------------------------------------------------------------
Traceback (most recent call last):
File "####/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "####/ex48/tests/parser_tests.py", line 8, in test_except
assert_raises(ParserError, parse_sentence(raw_sentence))
File "####/ex48/ex48/parser.py", line 69, in parse_sentence
obj = parse_object(word_list)
File "####/ex48/ex48/parser.py", line 53, in parse_object
raise ParserError("Expected a noun or direction next.")
ParserError: Expected a noun or direction next.
----------------------------------------------------------------------
Ran 8 tests in 0.008s
FAILED (errors=1)
Here is where the exception is coming from:
def parse_verb(word_list):
skip(word_list, 'stop')
if peek(word_list) == 'verb':
return match(word_list, 'verb')
else:
raise ParserError("Expected a verb next.")
The call to parse_sentence(raw_sentence)
is expected to fail. The assert_raises()
should work properly, but it doesn't catch the raised exception from parse_verb()
yielding a failed test. What do you think is/are the problem/s?
python python-2.7
I'm halfway through the book Learn Python the Hard Way by Zed Shaw. The book doesn't have any coverage or documentation for the function assert_raises()
.
So I tried to run this test:
from nose.tools import *
from ex48.parser import *
def test_except():
raw_sentence = [('stop', 'the'), ('noun', 'bear'), ('verb', 'kill')]
assert_raises(ParserError, parse_sentence(raw_sentence))
Here's the error when I tried to run nosetests
:
======================================================================
ERROR: tests.parser_tests.test_except
----------------------------------------------------------------------
Traceback (most recent call last):
File "####/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "####/ex48/tests/parser_tests.py", line 8, in test_except
assert_raises(ParserError, parse_sentence(raw_sentence))
File "####/ex48/ex48/parser.py", line 69, in parse_sentence
obj = parse_object(word_list)
File "####/ex48/ex48/parser.py", line 53, in parse_object
raise ParserError("Expected a noun or direction next.")
ParserError: Expected a noun or direction next.
----------------------------------------------------------------------
Ran 8 tests in 0.008s
FAILED (errors=1)
Here is where the exception is coming from:
def parse_verb(word_list):
skip(word_list, 'stop')
if peek(word_list) == 'verb':
return match(word_list, 'verb')
else:
raise ParserError("Expected a verb next.")
The call to parse_sentence(raw_sentence)
is expected to fail. The assert_raises()
should work properly, but it doesn't catch the raised exception from parse_verb()
yielding a failed test. What do you think is/are the problem/s?
python python-2.7
python python-2.7
asked May 21 '17 at 7:04
Bruce JimenezBruce Jimenez
32
32
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Do not call parse_sentence()
directly. Instead, pass it as an argument.
assert_raises(ParserError, parse_sentence, raw_sentence)
Even better, use assert_raises()
in a with
block. See How to use nose's assert_raises?
add a comment |
This will work
assert_raises(ParserError, parse_verb, raw_sentence)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44094078%2fassert-raises-from-nose-tools-wont-work-right%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Do not call parse_sentence()
directly. Instead, pass it as an argument.
assert_raises(ParserError, parse_sentence, raw_sentence)
Even better, use assert_raises()
in a with
block. See How to use nose's assert_raises?
add a comment |
Do not call parse_sentence()
directly. Instead, pass it as an argument.
assert_raises(ParserError, parse_sentence, raw_sentence)
Even better, use assert_raises()
in a with
block. See How to use nose's assert_raises?
add a comment |
Do not call parse_sentence()
directly. Instead, pass it as an argument.
assert_raises(ParserError, parse_sentence, raw_sentence)
Even better, use assert_raises()
in a with
block. See How to use nose's assert_raises?
Do not call parse_sentence()
directly. Instead, pass it as an argument.
assert_raises(ParserError, parse_sentence, raw_sentence)
Even better, use assert_raises()
in a with
block. See How to use nose's assert_raises?
edited May 23 '17 at 11:33
Community♦
11
11
answered May 21 '17 at 7:16
Jim KJim K
7,73111033
7,73111033
add a comment |
add a comment |
This will work
assert_raises(ParserError, parse_verb, raw_sentence)
add a comment |
This will work
assert_raises(ParserError, parse_verb, raw_sentence)
add a comment |
This will work
assert_raises(ParserError, parse_verb, raw_sentence)
This will work
assert_raises(ParserError, parse_verb, raw_sentence)
edited Mar 8 at 1:13
Trent
1,5392036
1,5392036
answered Mar 8 at 0:02
Kaushik PalKaushik Pal
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44094078%2fassert-raises-from-nose-tools-wont-work-right%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown