-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
67 lines (53 loc) · 2.33 KB
/
tests.py
File metadata and controls
67 lines (53 loc) · 2.33 KB
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
62
63
64
65
66
import pytest
import pandas as pd
import pandera.pandas as pa
from dataset_schema import aggregated_news_schema, vectorized_news_skipgram_schema, vectorized_news_cbow_schema
import os
# Define the directory where your datasets are stored
DATASET_DIR = "datasets"
def load_and_validate_csv(filepath, schema):
df = pd.read_csv(filepath)
schema.validate(df, lazy=True)
return df
def test_aggregated_news_schema_validation():
filename = "aggregated_news.csv"
filepath = os.path.join(DATASET_DIR, filename)
print(f"Validating {filepath} against schema: aggregated_news_schema")
try:
df = load_and_validate_csv(filepath, aggregated_news_schema)
except FileNotFoundError:
pytest.fail(f"File not found: {filepath}")
try:
aggregated_news_schema.validate(df, lazy=True)
print(f"Validation successful for {filepath}")
except pa.errors.SchemaErrors as err:
error_message = f"Schema validation failed for {filepath}:\n"
pytest.fail(error_message)
def test_vectorized_news_skipgram_embeddings():
filename = "vectorized_news_skipgram_embeddings.csv"
filepath = os.path.join(DATASET_DIR, filename)
print(f"Validating {filepath} against schema: vectorized_news_skipgram_schema")
try:
df = load_and_validate_csv(filepath, vectorized_news_skipgram_schema)
except FileNotFoundError:
pytest.fail(f"File not found: {filepath}")
try:
vectorized_news_skipgram_schema.validate(df, lazy=True)
print(f"Validation successful for {filepath}")
except pa.errors.SchemaErrors as err:
error_message = f"Schema validation failed for {filepath}:\n"
pytest.fail(error_message)
def test_vectorized_news_cbow_embeddings():
filename = "vectorized_news_cbow_embeddings.csv"
filepath = os.path.join(DATASET_DIR, filename)
print(f"Validating {filepath} against schema: vectorized_news_cbow_schema")
try:
df = load_and_validate_csv(filepath, vectorized_news_cbow_schema)
except FileNotFoundError:
pytest.fail(f"File not found: {filepath}")
try:
vectorized_news_cbow_schema.validate(df, lazy=True)
print(f"Validation successful for {filepath}")
except pa.errors.SchemaErrors as err:
error_message = f"Schema validation failed for {filepath}:\n"
pytest.fail(error_message)