Skip to content

Commit 5659574

Browse files
committed
ex 02-3
1 parent b0c6acb commit 5659574

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

.learn/exercises/02.2-create-script/test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ def test_file_existence():
55
file = os.path.abspath(__file__)+'/app.py'
66
assert file != None
77

8-
@pytest.mark.it('Use print function')
8+
@pytest.mark.it("Use the print function")
9+
def test_output():
10+
f = open(os.path.dirname(os.path.abspath('app.py'))+'/app.py')
11+
content = f.read()
12+
assert content.find("print(") > 0
13+
14+
@pytest.mark.it('The output should be the expected: Hello World')
915
def test_print(capsys):
1016
import app
1117
captured = capsys.readouterr()

.learn/exercises/02.3-import_pandas/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Import pandas
1+
# `02.3` Import pandas
22

33
Now let's add Pandas into our script by using the `import` command.
44

55
The `import` command is meant for loading 3rd part libraries (like pandas) or other python files that you have created (which we will do in the future)
66

77
## 📝 Instructions
88

9-
1. Type `import pandas as pd` inside the file to import the pandas library.
9+
1. Type `import pandas as pd` inside the file `app.py` to import the pandas library.
1010
2. Use the pandas read_csv function to import the content of the CSV file into a variable.
1111
3. print the variable on the terminal using the `print` function.
1212

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import io, os, sys, pytest, re, pandas
2+
data = pandas.read_csv('.learn/assets/pokemon_data.csv')
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('The variable data_frame must exist')
13+
def test_vatiable_existence():
14+
from app import data_frame
15+
16+
@pytest.mark.it("Use the print function")
17+
def test_output():
18+
f = open(os.path.dirname(os.path.abspath('app.py')) + '/app.py')
19+
content = f.read()
20+
assert content.find("print(") > 0
21+
22+
@pytest.mark.it('The output should be the expected')
23+
def test_output_print(capsys):
24+
from app import data_frame
25+
result = data_frame.empty == False and data.empty == False
26+
assert result == True

.learn/vscode_queue.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
print('Hello World')
1+
import pandas as pd
2+
3+
data_frame = pd.read_csv('.learn/assets/pokemon_data.csv')
4+
print(data_frame)
5+

conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys, os, json
22
if os.path.isdir("./.venv/lib/"):
3-
sys.path.append('null/site-packages')
3+
sys.path.append('./.venv/lib/python3.8/site-packages')
44
def pytest_addoption(parser):
55
parser.addoption("--stdin", action="append", default=[],
66
help="json with the stdin to pass to test functions")
@@ -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":1326614059129245200,"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":2664118464753879600,"translations":[]}')])

0 commit comments

Comments
 (0)