Skip to content

Commit b97e173

Browse files
committed
ex 05.1, 05.2, 05.3, 05.4
1 parent e09e168 commit b97e173

File tree

7 files changed

+117
-10
lines changed

7 files changed

+117
-10
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pytest, io, os, sys, re
2+
3+
@pytest.mark.it('You must import pandas')
4+
def test_import_pandas():
5+
path = os.path.dirname(os.path.abspath('app.py'))+'/app.py'
6+
with open(path, 'r') as content_file:
7+
content = content_file.read()
8+
regex = re.compile(r"import\s*pandas")
9+
assert bool(regex.search(content)) == True
10+
11+
@pytest.mark.it("Use the print function")
12+
def test_output():
13+
f = open(os.path.dirname(os.path.abspath('app.py')) + '/app.py')
14+
content = f.read()
15+
assert content.find("print") > 0
16+
17+
18+
@pytest.mark.it('The output should be the expected')
19+
def test_expected_output(capsys):
20+
import app
21+
captured = capsys.readouterr()
22+
assert captured.out == """ brand make color
23+
0 Toyota Corolla Blue
24+
1 Ford K Yellow
25+
2 Porche Cayenne White
26+
3 Tesla Model S Red
27+
"""

.learn/exercises/05.2-iloc/solution.hiden.py

Whitespace-only changes.

.learn/exercises/05.2-iloc/test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest, io, os, sys, re
2+
3+
@pytest.mark.it('You must import pandas')
4+
def test_import_pandas():
5+
path = os.path.dirname(os.path.abspath('app.py'))+'/app.py'
6+
with open(path, 'r') as content_file:
7+
content = content_file.read()
8+
regex = re.compile(r"import\s*pandas")
9+
assert bool(regex.search(content)) == True
10+
11+
@pytest.mark.it("Use the print function")
12+
def test_output():
13+
f = open(os.path.dirname(os.path.abspath('app.py')) + '/app.py')
14+
content = f.read()
15+
assert content.find("print") > 0
16+
17+
18+
@pytest.mark.it('The output should be the expected')
19+
def test_expected_output(capsys):
20+
import app
21+
captured = capsys.readouterr()
22+
assert captured.out == ""

.learn/exercises/05.3-head/test.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pytest, io, os, sys, re, pandas
2+
data_frame = pandas.read_csv('.learn/assets/pokemon_data.csv').head(3)
3+
4+
@pytest.mark.it('You must import pandas')
5+
def test_import_pandas():
6+
path = os.path.dirname(os.path.abspath('app.py'))+'/app.py'
7+
with open(path, 'r') as content_file:
8+
content = content_file.read()
9+
regex = re.compile(r"import\s*pandas")
10+
assert bool(regex.search(content)) == True
11+
12+
@pytest.mark.it("Use the print function")
13+
def test_output():
14+
f = open(os.path.dirname(os.path.abspath('app.py')) + '/app.py')
15+
content = f.read()
16+
assert content.find("print") > 0
17+
18+
19+
@pytest.mark.it('The output should be the expected')
20+
def test_expected_output(capsys):
21+
import app
22+
captured = capsys.readouterr()
23+
assert captured.out == str(data_frame) + '\n'
24+
25+
# @pytest.mark.it('The variable data_frame should exist')
26+
# def test_variable_existence():
27+
# from app import data_frame
28+
29+
"""
30+
# Name Type 1 Type 2 HP Attack Defense Sp. Atk Sp. Def Speed Generation Legendary
31+
0 1 Bulbasaur Grass Poison 45 49 49 65 65 45 1 False
32+
1 2 Ivysaur Grass Poison 60 62 63 80 80 60 1 False
33+
2 3 Venusaur Grass Poison 80 82 83 100 100 80 1 False
34+
"""

.learn/exercises/05.4-tail/test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import io, os, re, sys, pytest, pandas
2+
data_frame = pandas.read_csv('.learn/assets/pokemon_data.csv').tail(3)
3+
4+
@pytest.mark.it('You must import pandas')
5+
def test_import_pandas():
6+
path = os.path.dirname(os.path.abspath('app.py'))+'/app.py'
7+
with open(path, 'r') as content_file:
8+
content = content_file.read()
9+
regex = re.compile(r"import\s*pandas")
10+
assert bool(regex.search(content)) == True
11+
12+
@pytest.mark.it("Use the print function")
13+
def test_output():
14+
f = open(os.path.dirname(os.path.abspath('app.py')) + '/app.py')
15+
content = f.read()
16+
assert content.find("print") > 0
17+
18+
19+
@pytest.mark.it('The output should be the expected')
20+
def test_expected_output(capsys):
21+
import app
22+
captured = capsys.readouterr()
23+
assert captured.out == str(data_frame)+'\n'
24+
25+
# @pytest.mark.it('The variable data_frame should exist')
26+
# def test_variable_existence():
27+
# from app import data_frame
28+
29+
""" # Name Type 1 Type 2 HP Attack Defense Sp. Atk Sp. Def Speed Generation Legendary
30+
797 720 HoopaHoopa Confined Psychic Ghost 80 110 60 150 130 70 6 True
31+
798 720 HoopaHoopa Unbound Psychic Dark 80 160 60 170 130 80 6 True
32+
799 721 Volcanion Fire Water 80 110 120 130 90 70 6 True
33+
"""

app.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
import pandas as pd
2-
# two dimensional array of name,age values.
3-
data = [["Toyota", "Corolla", "Blue"], ["Ford", "K", "Yellow"], ["Porche", "Cayenne", "White"]]
4-
5-
# create the dataframe and name the columns
6-
df = pd.DataFrame(data,columns=['Brand', 'Make', 'Color'])
7-
8-
# print the dataframe
9-
print(df)

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def pytest_generate_tests(metafunc):
2424
except AttributeError:
2525
metafunc.parametrize("app",[cached_app])
2626
if 'configuration' in metafunc.fixturenames:
27-
metafunc.parametrize("configuration", [json.loads('{"port":3000,"address":"https://kiddopro-pythonpandastut-zzjbcc6h0h1.ws-us34.gitpod.io","editor":{"mode":"preview","agent":"gitpod","version":"1.0.72"},"dirPath":"./.learn","configPath":"learn.json","outputPath":".learn/dist","publicPath":"/preview","publicUrl":"https://3000-kiddopro-pythonpandastut-zzjbcc6h0h1.ws-us34.gitpod.io","language":"auto","grading":"incremental","exercisesPath":".learn/exercises","webpackTemplate":null,"disableGrading":false,"disabledActions":["build"],"actions":[],"entries":{"html":"index.html","vanillajs":"index.js","react":"app.jsx","node":"app.js","python3":"app.py","java":"app.java"},"preview":"https://github.com/4GeeksAcademy/python-pandas-tutorial/blob/main/.learn/assets/pandas-preview.jpeg?raw=true","difficulty":"beginner","duration":3,"description":"Learn the basics and become comfortable using pandas for manipulating machine learning datasets .","title":"Pandas for Machine Learning","slug":"pandas-for-machine-learning","session":4383489070513313300,"translations":[]}')])
27+
metafunc.parametrize("configuration", [json.loads('{"port":3000,"address":"https://kiddopro-pythonpandastu-mcial2n3lf7.ws-us41.gitpod.io","editor":{"mode":"preview","agent":"gitpod","version":"1.0.72"},"dirPath":"./.learn","configPath":"learn.json","outputPath":".learn/dist","publicPath":"/preview","publicUrl":"https://3000-kiddopro-pythonpandastu-mcial2n3lf7.ws-us41.gitpod.io","language":"auto","grading":"incremental","exercisesPath":".learn/exercises","webpackTemplate":null,"disableGrading":false,"disabledActions":["build"],"actions":[],"entries":{"html":"index.html","vanillajs":"index.js","react":"app.jsx","node":"app.js","python3":"app.py","java":"app.java"},"preview":"https://github.com/4GeeksAcademy/python-pandas-tutorial/blob/main/.learn/assets/pandas-preview.jpeg?raw=true","difficulty":"beginner","duration":3,"description":"Learn the basics and become comfortable using pandas for manipulating machine learning datasets .","title":"Pandas for Machine Learning","slug":"pandas-for-machine-learning","session":6793656476394450000,"translations":[]}')])

0 commit comments

Comments
 (0)