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 5e7a115

Browse files
Merge pull request #72 from kiddopro/14-Loop-dictionary
I have modified the tests, now the search is done with regex
2 parents 18e2a2c + 8e277cc commit 5e7a115

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

‎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*[\'\"]love[\'\"]\s*\]\s*\=\s*[\'\"]amor[\'\"]")
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*[\'\"]code[\'\"]\s*\]\s*\=\s*[\'\"]codigo[\'\"]")
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*[\'\"]smart[\'\"]\s*\]\s*\=\s*[\'\"]inteligente[\'\"]")
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 によって変換されたページ (->オリジナル) /