Skip to content

Commit 00cb987

Browse files
committed
ex 04, 04.1, 04.2
1 parent 922c135 commit 00cb987

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

.learn/exercises/04-Series/test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pytest, re, os, io, sys
1+
import pytest, io, os, sys, re
22

33
@pytest.mark.it('You must import pandas')
44
def test_import_pandas():
@@ -12,6 +12,12 @@ def test_import_pandas():
1212
def test_vatiable_existence():
1313
from app import ages
1414

15+
@pytest.mark.it("Use the print function")
16+
def test_output():
17+
f = open(os.path.dirname(os.path.abspath('app.py')) + '/app.py')
18+
content = f.read()
19+
assert content.find("print(") > 0
20+
1521
@pytest.mark.it('The output should be the expected')
1622
def test_expected_output(capsys):
1723
import app
@@ -27,5 +33,4 @@ def test_expected_output(capsys):
2733
8 54
2834
9 34
2935
dtype: int64
30-
3136
"""
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 == """DatetimeIndex(['2021-05-01', '2021-05-02', '2021-05-03', '2021-05-04',
23+
'2021-05-05', '2021-05-06', '2021-05-07', '2021-05-08',
24+
'2021-05-09', '2021-05-10', '2021-05-11', '2021-05-12'],
25+
dtype='datetime64[ns]', freq='D')
26+
"""
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import io, os, re, sys, pytest
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+
@pytest.mark.it('The variable my_series should exist')
18+
def test_variable_existence():
19+
from app import my_series
20+
21+
@pytest.mark.it('The output should be the expected')
22+
def test_expected_output(capsys):
23+
import app
24+
captured = capsys.readouterr()
25+
assert captured.out == """0 1.0
26+
1 2.0
27+
2 3.0
28+
3 4.0
29+
4 5.0
30+
dtype: float64"""

app.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pandas as pd
2-
# two dimensional array of name,age values.
3-
ages = pd.Series([23,45,7,34,6,63,36,78,54,34])
4-
5-
print(ages)
62

3+
my_series = pd.Series([2, 4, 6, 8, 10])
4+
modified_series = my_series.apply(lambda x:x/2)
5+
print(modified_series)

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":7340087717416326000,"translations":[]}')])
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":8607061631283586000,"translations":[]}')])

0 commit comments

Comments
 (0)