|
1 |
| -import io |
2 |
| -import os |
3 |
| -import sys |
4 |
| -sys.stdout = buffer = io.StringIO() |
5 |
| - |
6 |
| -import app |
7 |
| -import pytest |
8 |
| - |
9 |
| -@pytest.mark.it("Print the object") |
10 |
| -def test_output(): |
11 |
| - captured = buffer.getvalue() |
12 |
| - assert "{'total': 9, 'occupied': 5, 'available': 1}\n" in captured |
13 |
| - |
14 |
| -@pytest.mark.it("Create a get_parking_lot function") |
15 |
| -def test_function(): |
16 |
| - f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py') |
17 |
| - content = f.read() |
18 |
| - assert content.find("get_parking_lot") > 0 |
19 |
| - |
20 |
| -@pytest.mark.it("Make a for loop") |
21 |
| -def test_for(): |
22 |
| - f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py') |
23 |
| - content = f.read() |
24 |
| - assert content.find("for") > 0 |
25 |
| - |
26 |
| - |
27 |
| - |
28 |
| -@pytest.mark.it("Using conditional statements") |
29 |
| -def test_conditional(): |
30 |
| - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') |
31 |
| - content = f.read() |
32 |
| - assert content.find('if') > 0 |
33 |
| - assert content.find('elif') > 0 |
34 |
| - |
35 |
| -@pytest.mark.it("Push the value into the new variables") |
36 |
| -def test_append(): |
37 |
| - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') |
38 |
| - content = f.read() |
39 |
| - assert content.find('append') > 0 |
| 1 | +import io, sys, pytest, os, re |
| 2 | +path = os.path.dirname(os.path.abspath(__file__))+'/app.py' |
| 3 | + |
| 4 | +@pytest.mark.it("Print the updated state ") |
| 5 | +def test_output(capsys, app): |
| 6 | + import app |
| 7 | + captured = capsys.readouterr() |
| 8 | + assert "{'total_slots': 6, 'available_slots': 1, 'occupied_slots': 5}\n" in captured.out |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.it("Create the function get_parking_lot") |
| 12 | +def test_variable_exists(app): |
| 13 | + try: |
| 14 | + app.get_parking_lot |
| 15 | + except AttributeError: |
| 16 | + raise AttributeError("The function get_parking_lot should exist on app.py") |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
40 | 21 |
|
41 | 22 |
|
42 | 23 |
|
0 commit comments