Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e0a7971

Browse files
committed
fixed the tests, now we use regex to search into the file
1 parent 6caec3e commit e0a7971

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed
374 Bytes
Binary file not shown.
4.02 KB
Binary file not shown.

‎exercises/14-Loop-dictionary/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
21
spanish_translations = { "dog": "perro", "house": "casa", "cat": "gato" }
2+
# Your code here
33

44

5-
5+
# Don't touch the code below
66
print("Translation", spanish_translations["dog"])
7-
print("All", spanish_translations)
7+
print(spanish_translations)
88

‎exercises/14-Loop-dictionary/test.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,25 @@
55
def test_love():
66
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
77
content = f.read()
8-
value = False
9-
if(content.find("spanish_translations['love'] = 'amor'") > 0 or content.find('spanish_translations["love"] = "amor"') > 0):
10-
value = True
11-
assert value == True
8+
regex = re.compile(r"spanish_translations\[\s*[\'\"]\s*love\s*[\'\"]\s*\]\s*\=\s*[\'\"]\s*amor\s*[\'\"]")
9+
assert bool(regex.search(content)) == True
1210

1311
@pytest.mark.it("You should add `code` programatically to the dictionary")
1412
def test_code():
1513
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
1614
content = f.read()
17-
value = False
18-
if(content.find("spanish_translations['code'] = 'codigo'") > 0 or content.find('spanish_translations["code"] = "codigo"') > 0):
19-
value = True
20-
assert value == True
15+
regex = re.compile(r"spanish_translations\[\s*[\'\"]\s*code\s*[\'\"]\s*\]\s*\=\s*[\'\"]\s*codigo\s*[\'\"]")
16+
assert bool(regex.search(content)) == True
2117

2218
@pytest.mark.it("You should add `smart` programatically to the dictionary")
2319
def test_smart():
2420
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
2521
content = f.read()
26-
value = False
27-
if(content.find("spanish_translations['smart'] = 'inteligente'") > 0 or content.find('spanish_translations["smart"] = "inteligente"') > 0):
28-
value = True
29-
assert value == True
22+
regex = re.compile(r"spanish_translations\[\s*[\'\"]\s*smart\s*[\'\"]\s*\]\s*\=\s*[\'\"]\s*inteligente\s*[\'\"]")
23+
assert bool(regex.search(content)) == True
3024

3125
@pytest.mark.it("You should print in the console the dictionary with proper translations")
3226
def test_multp(capsys, app):
3327
import app
3428
captured = capsys.readouterr()
35-
assert "All {'dog': 'perro', 'house': 'casa', 'cat': 'gato', 'love': 'amor', 'code': 'codigo', 'smart': 'inteligente'}" in captured.out
29+
assert "{'dog': 'perro', 'house': 'casa', 'cat': 'gato', 'love': 'amor', 'code': 'codigo', 'smart': 'inteligente'}" in captured.out

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /