Skip to content

Commit cbccaaa

Browse files
committed
updated test until exercise 11
1 parent c683a41 commit cbccaaa

File tree

21 files changed

+184
-204
lines changed

21 files changed

+184
-204
lines changed

exercises/01-Console/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import os
77
import pytest
88

9-
@pytest.mark.it('1. You need to use the function print()')
9+
@pytest.mark.it('Use the function print()')
1010
def test_for_file_output(capsys):
1111
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1212
with open(path, 'r') as content_file:
1313
content = content_file.read()
1414
regex = r"print\("
1515
assert re.match(regex, content) != None
1616

17-
@pytest.mark.it('2. Your code needs to print Hello World! on the console')
17+
@pytest.mark.it('Print Hello World! on the console')
1818
def test_for_console_log(capsys):
1919
captured = buffer.getvalue()
2020
assert captured == "Hello World!\n" #add \n because the console jumps the line on every print

exercises/02-Declare-Variables/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77
import os
88
import re
99

10-
@pytest.mark.it('1. You need to use the function print()')
10+
@pytest.mark.it('Use the function print()')
1111
def test_for_print():
1212
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1313
with open(path, 'r') as content_file:
1414
content = content_file.read()
1515
regex = re.compile(r"print\(['\"]?.+['\"]?\)")
1616
assert bool(regex.search(content)) == True
1717

18-
@pytest.mark.it('2. Declare a variable and assign it the value "Yellow"')
18+
@pytest.mark.it('Declare a variable and assign it the value "Yellow"')
1919
def test_for_variable():
2020
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
2121
with open(path, 'r') as content_file:
2222
content = content_file.read()
2323
regex = re.compile(r"\w*(\s*)=(\s*)\"Yellow\"")
2424
assert bool(regex.search(content)) == True
2525

26-
@pytest.mark.it('3. Your code needs to print Yellow on the console')
26+
@pytest.mark.it('Print "Yellow" on the console')
2727
def test_for_file_output(capsys):
2828
captured = buffer.getvalue()
2929
assert captured == "Yellow\n" #add \n because the console jumps the line on every print

exercises/03-Print-Variables-In-The-Console/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
import os
99
import re
1010

11-
@pytest.mark.it("1. Create a variable named 'color' with the string value red")
11+
@pytest.mark.it("Create a variable named 'color' with the string value red")
1212
def test_declare_variable():
1313
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
1414
with open(path, 'r') as content_file:
1515
content = content_file.read()
1616
regex = re.compile(r"color(\s*)=(\s*)\"red\"")
1717
assert bool(regex.search(content)) == True
1818

19-
@pytest.mark.it('2. You should print on the console the value of the variable ')
19+
@pytest.mark.it('Print on the console the value of the variable ')
2020
def test_for_printing_variable():
2121
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
2222
with open(path, 'r') as content_file:
2323
content = content_file.read()
2424
regex = re.compile(r"print(\s*)\(color\)")
2525
assert bool(regex.search(content)) == True
2626

27-
@pytest.mark.it('3. The printed value on the console should be "red"')
27+
@pytest.mark.it('The printed value on the console should be "red"')
2828
def test_for_file_output(capsys):
2929
captured = buffer.getvalue()
3030
assert captured == "red\n"

exercises/04-Multiply-Two-Values/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
import app
99
import re
1010

11-
@pytest.mark.it('1. You should create a variable named variables_are_cool')
11+
@pytest.mark.it('You should create a variable named variables_are_cool')
1212
def test_variable_exists():
1313
try:
1414
from app import variables_are_cool
1515
except ImportError:
1616
raise ImportError("The variable 'variables_are_cool' should exist on app.py")
1717

18-
@pytest.mark.it('2. variables_are_cool value should be like 2345 * 7323 ')
18+
@pytest.mark.it('Variables_are_cool value should be like 2345 * 7323 ')
1919
def test_use_variable_name():
2020
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
2121
with open(path, 'r') as content_file:
2222
content = content_file.read()
2323
regex = re.compile(r"variables_are_cool(\s*)=(\s*)2345(\s*)\*(\s*)7323")
2424
assert bool(regex.search(content)) == True
2525

26-
@pytest.mark.it('3. You should print on the console the variables_are_cool value ')
26+
@pytest.mark.it('Print on the console the variables_are_cool value ')
2727
def test_for_file_output(capsys):
2828

2929
from app import variables_are_cool
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
age = int(input('What is your age?\n'))
22
# CHANGE THE CODE BELOW TO ADD 10 TO AGE
3-
43
print("Your age is: "+str(age))

exercises/05-User-Inputed-Values/test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import pytest,os,re,io,sys, mock, json
22

3-
@pytest.mark.it("1. You should print on the console the input value + 10")
3+
@pytest.mark.it("Print on the console the input value + 10")
44
def test_t(stdin):
55
_input = json.loads(stdin)
6-
print("####", _input[0])
76
my_testString = int(_input[0]) + 10
8-
print("$$$$$:",int(my_testString) + 10)
97
with mock.patch('builtins.input', lambda x: _input.pop()):
108
# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
119
sys.stdout = buffer = io.StringIO()

exercises/06-String-Concatenation/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Set the values here
1+
# Set the values for my_var1 and my_var2 here
22

33

44
## Don't change below this line
Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,34 @@
1-
import io
2-
import sys
1+
import io, sys, os, re, pytest
32
sys.stdout = buffer = io.StringIO()
43

5-
# from app import my_function
6-
import pytest
74
import app
8-
import os
9-
import re
105

6+
@pytest.mark.it("Create a variable named my_var1")
7+
def test_my_var1_exists():
8+
try:
9+
from app import my_var1
10+
except ImportError:
11+
raise ImportError("The variable 'my_var1' should exist on app.py")
1112

12-
@pytest.mark.it("1. You should create a variable named my_var1")
13-
def test_use_my_var1():
14-
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
15-
content = f.readlines()
16-
content = [x.strip() for x in content]
17-
my_var1 = [s for s in content if "my_var1" in s]
18-
my_var1Var = content.index(my_var1[0])
19-
regex_my_var1 = r"my_var1(\s*)=(\s*)\"(\s*)Hello(\s*)\""
20-
# regex = r"color = \"red\""
21-
# regex = r"color(\s*)=(\s*)\"red\""
22-
assert re.match(regex_my_var1, content[my_var1Var])
23-
@pytest.mark.it("2. You should create a variable named my_var2")
24-
def test_use_my_var2():
25-
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
26-
content = f.readlines()
27-
content = [x.strip() for x in content]
28-
my_var2 = [s for s in content if "my_var2" in s]
29-
my_var2Var = content.index(my_var2[0])
30-
regex_my_var2 = r"my_var2(\s*)=(\s*)\"(\s*)World(\s*)\""
31-
# regex = r"color = \"red\""
32-
# regex = r"color(\s*)=(\s*)\"red\""
33-
assert re.match(regex_my_var2, content[my_var2Var])
34-
@pytest.mark.it('3. Your code needs to print Hello World on the console')
35-
def test_for_file_output(capsys):
13+
14+
@pytest.mark.it("Create a variable named my_var2")
15+
def test_my_var2_exists():
16+
try:
17+
from app import my_var2
18+
except ImportError:
19+
raise ImportError("The variable 'my_var2' should exist on app.py")
3620

37-
captured = buffer.getvalue()
38-
assert captured == "Hello World\n" #add \n because the console jumps the line on every print
21+
@pytest.mark.it("Variable my_var1 value should be 'Hello'")
22+
def test_my_var1_value():
23+
from app import my_var1
24+
assert my_var1 == "Hello"
3925

40-
# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console')
41-
# def test_for_function_output(capsys):
42-
# my_function()
43-
# captured = capsys.readouterr()
44-
# assert captured.out == "Hello Inside Function\n"
26+
@pytest.mark.it("Variable my_var2 value should be 'World'")
27+
def test_my_var1_value():
28+
from app import my_var2
29+
assert my_var2 == "World"
4530

46-
# @pytest.mark.it('Your function needs to return True')
47-
# def test_for_function_return(capsys):
48-
# assert my_function() == True
31+
@pytest.mark.it('Print "Hello World" on the console')
32+
def test_for_file_output():
33+
captured = buffer.getvalue()
34+
assert captured == "Hello World\n" #add \n because the console jumps the line on every print

exercises/07-Create-a-Basic-HTML/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ Let's continue using string concatenation to generate HTML...
77

88
## 📝 Instructions:
99

10-
1. The code on the left contains 8 variables with different string values, please use
11-
the variables and concatenate them together to set the value of the variable **html_document**
10+
1. Create a variable **html_document**
11+
12+
2. The code on the left contains 8 variables with different string values, please use
13+
the variables concatenating them together to set the value of the variable **html_document**
1214
a new string that has the content of a typical HTML document (with the HTML tags in the
1315
right order).
1416

15-
2. Then, print the value of **html_document** on the console.
17+
3. Then, print the value of **html_document** on the console.
1618

1719
The output should look like this:
1820

exercises/07-Create-a-Basic-HTML/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
g = '<title>'
88
h = '<body>'
99

10-
# DON'T CHANGE THE CODE ABOVE
10+
# ⬆ DON'T CHANGE THE CODE ABOVE ⬆
11+
# ↓ start coding below here ↓
1112

0 commit comments

Comments
 (0)