-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_luffy.py
49 lines (44 loc) · 1.53 KB
/
test_luffy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from os.path import exists
import pytest
import csv
import requests
import codecs
if exists('../src/Cargo.py'):
from src.Ship import Ship
else:
from src.ships import Ship
if exists('../src/Cargo.py'):
from src.Cruise import Cruise
else:
from src.ships import Cruise
if exists('../src/Cargo.py'):
from src.Cargo import Cargo
else:
from src.ships import Cargo
def test_with_file():
url="https://my.api.mockaroo.com/oop_pirate.csv?key=44ac9940"
try:
ShipLists = csv.reader(codecs.iterdecode(requests.get(url).iter_lines(), encoding="utf-8"), delimiter=",")
except (requests.exceptions.ConnectionError, requests.exceptions.RequestException):
...
else:
myShips: list[any] = []
header: bool = True
for ship in ShipLists:
if not header:
try:
if ship[2] == '' and ship[3] == '':
myShips.append(Ship(int(ship[0]), int(ship[1])))
elif ship[3] == '':
myShips.append(Cruise(int(ship[2]), int(ship[0]), int(ship[1])))
else:
if ship[2] == '':
continue
myShips.append(Cargo(int(ship[2]), float(ship[3]), int(ship[0]), int(ship[1])))
except ValueError:
continue
else:
header = False
with pytest.raises(ValueError):
for ship_ in myShips:
assert (ship_.is_worth_it() >= 20) == True