-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_schema_out.py
61 lines (48 loc) · 1.83 KB
/
test_schema_out.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
50
51
52
53
54
55
56
57
58
59
60
61
import pandas as pd
import pandera as pa
import pytest
from src.schema import CompanyRevenueTransformed
def test_valid_schema():
df = pd.DataFrame({
'company': ['ABC Inc', 'company', 'Company 02'],
'currency': ['EUR', 'EUR', 'EUR'],
'operational_revenue': [1000, 2000, 3],
'date': ['March 2022', '2022-03', '2022/03'],
'file_id': ['str1', 'str2', 'str3'],
'convertion_rate': [1, 2, 3],
'usd_converted': [30, 40, 50]
})
CompanyRevenueTransformed.validate(df)
def test_missing_file_id():
df = pd.DataFrame({
'company': ['ABC Inc', 'company', 'Company 02'],
'currency': ['EUR', 'EUR', 'EUR'],
'operational_revenue': [1000, 2000, 3],
'date': ['March 2022', '2022-03', '2022/03'],
'convertion_rate': [1, 2, 3],
'usd_converted': [30, 40, 50]
})
with pytest.raises(pa.errors.SchemaErrors):
CompanyRevenueTransformed.validate(df, lazy=True)
def test_rate_negative():
df = pd.DataFrame({
'company': ['ABC Inc', 'company', 'Company 02'],
'currency': ['EUR', 'EUR', 'EUR'],
'operational_revenue': [1000, 2000, 3],
'date': ['March 2022', '2022-03', '2022/03'],
'convertion_rate': [-1, 2, 3],
'usd_converted': [30, 40, 50]
})
with pytest.raises(pa.errors.SchemaErrors):
CompanyRevenueTransformed.validate(df, lazy=True)
def test_usd_converted_negative():
df = pd.DataFrame({
'company': ['ABC Inc', 'company', 'Company 02'],
'currency': ['EUR', 'EUR', 'EUR'],
'operational_revenue': [1000, 2000, 3],
'date': ['March 2022', '2022-03', '2022/03'],
'convertion_rate': [1, 2, 3],
'usd_converted': [30, -40, 50]
})
with pytest.raises(pa.errors.SchemaErrors):
CompanyRevenueTransformed.validate(df, lazy=True)