Вопрос

So I'm trying to write a test for part of a word parser function that will basically confirm whether or not the parser will return what it's supposed to. The part I'm writing a test for is a function called "peek" where it takes a list of tuples (tuples that are in the ('TYPE', 'WORD') format), and returns the value in the 'TYPE' part of the tuple. The code for the peek part of the parser (which is in the file parser.py) is as follows:

def peek(word_list):
if word_list:
    word = word_list[0]
    return word[0]
else:
    return None

where "word_list" is the list of tuples in question. My test, then, is basically designed to see if the peek function does indeed recognize the tuple list in "word_list" and returns the 'TYPE' value from the tuples it goes through. My code for this test is as follows:

from nose.tools import *
from ex49 import parser


def test_peek():

    word_list = [('direction', 'north')]
    assert_equal(parser.peek([('direction', 'north')], 'direction')
    result = parser.peek(word_list)
    assert_equal(result, ['direction'])

That looks like it should be right, but when I run the nosetests, all I get is this error message:

    result = parser.peek(word_list)
         ^
SyntaxError: invalid syntax

I double and triple-checked all my parentheses, commas, operators, and variable values, and I see no SyntaxError, or anything that would lead me to believe something would cause a SyntaxError. Is there something I'm missing here? Any insight would be much appreciated.

Thanks

Это было полезно?

Решение

It's just a missing close paren from the previous line:

assert_equal(parser.peek([('direction', 'north')], 'direction')  # <-- ) here
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top