Skip to content

Commit a9bbd95

Browse files
authored
[MAINTAINCE] read config file instead using datacontext (#74)
* feat: read config file
1 parent 3d10d13 commit a9bbd95

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

functions/data_test/profiling.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
from Expectation_report_new import ExpectationsReportNew
99
from pandas_profiling.expectations_report import ExpectationsReport
1010
from datetime import datetime
11-
from great_expectations import DataContext
1211
from great_expectations.data_context import BaseDataContext
1312
from great_expectations.data_context.types.base import (DataContextConfig,
1413
S3StoreBackendDefaults)
1514
import yaml
16-
15+
DEFAULT_CONFIG_FILE_PATH = "great_expectations/great_expectations.yml"
1716

1817
if os.environ['ENVIRONMENT'] == 'local':
1918
endpoint_url = f"http://{os.environ['S3_HOST']}:{os.environ['S3_PORT']}"
@@ -66,11 +65,7 @@ def __init__(self, typeset, *args, **kwargs):
6665

6766

6867
def change_ge_config(datasource_root):
69-
context_ge = DataContext()
70-
71-
configfile_raw = context_ge.get_config().to_yaml_str()
72-
configfile = yaml.safe_load(configfile_raw)
73-
68+
configfile = read_gx_config_file()
7469
datasources = {
7570
"pandas_s3": {
7671
"class_name": "PandasDatasource",
@@ -151,7 +146,15 @@ def remove_suffix(input_string, suffix):
151146
return input_string
152147

153148

154-
def profile_data(df, suite_name, cloudfront, datasource_root, source_covered,
149+
def read_gx_config_file(path=None) -> dict:
150+
if path is None:
151+
path = DEFAULT_CONFIG_FILE_PATH
152+
with open(path, "r") as config_file:
153+
configfile = yaml.safe_load(config_file)
154+
return configfile
155+
156+
157+
def profile_data(df, suite_name, cloudfront, datasource_root, source_covered,
155158
mapping_config, run_name):
156159
qa_bucket = s3.Bucket(qa_bucket_name)
157160
config = change_ge_config(datasource_root)
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import pytest
2-
from functions.data_test.profiling import (add_local_s3_to_stores)
2+
from functions.data_test.profiling import (add_local_s3_to_stores,
3+
read_gx_config_file)
4+
5+
ENDPOINT_URL = "http://localhost:4566"
36

47

58
@pytest.mark.parametrize("stores, expected_output", [
69
({"store1": {"store_backend": {"type": "s3", "bucket": "my-bucket"}}},
7-
{"store1": {"store_backend": {"type": "s3", "bucket": "my-bucket", "boto3_options": {"endpoint_url": "http://localhost:4566"}}}}),
10+
{"store1": {"store_backend": {"type": "s3", "bucket": "my-bucket",
11+
"boto3_options":
12+
{"endpoint_url": ENDPOINT_URL}}}}),
813
({}, {})
914
])
1015
def test_add_local_s3_to_stores(stores, expected_output):
11-
endpoint_url = "http://localhost:4566"
12-
assert add_local_s3_to_stores(stores, endpoint_url) == expected_output
16+
assert add_local_s3_to_stores(stores, ENDPOINT_URL) == expected_output
17+
18+
19+
def test_gx_config_file():
20+
config_file = read_gx_config_file()
21+
assert config_file["config_version"] == 2.0
22+
23+
24+
def test_gx_config_file_path_is_not_none(tmpdir):
25+
p = tmpdir.mkdir("config").join("great_expectations.yml")
26+
p.write("config_version: 10.0")
27+
config_file = read_gx_config_file(path=p)
28+
assert config_file["config_version"] == 10.0

0 commit comments

Comments
 (0)