The Ascend Python Test Framework
Project description
This package helps developers who are writing custom python for Ascend.io automated pipelines by providing a local testing framework. Local testing speeds the development of python pipeline code. The local framework exercises the code as if the code was running directly in the platform while giving you access to patching and mocking frameworks.
Documentation, including examples, is located in our Ascend Developer Hub.
Example
Here is a basic python transformation test case example. The python code under test is located in a file with the name my_python_transform.py and imported with the name my_python_transform. Other variables, imports, and code are omitted for brevity:
@AscendPySparkTransform(spark=spark_session, module=my_python_transform, schema=input_schema, data=[(123, 'NORMAL', today, today + datetime.timedelta(days=1))], credentials=test_creds, discover_schema=True, patches=[patch('requests.post', return_value=Mock(status_code=200, text='{"internalReportIds":"REPORT_A"}')), patch('requests.get', return_value=Mock(status_code=200, text='{"status":"SUCCESS", "downloadLink": "https://test.my.download"}')), patch('pandas.read_csv', return_value=build_mock_csv()), ], ) def test_normal_loading_process_single_record(input_dataframe, transform_result: DataFrame, mock_results: List[Mock]): """Check that a normal call does the work properly. Assert values are correct. Assert mock services are called.""" assert input_dataframe assert transform_result assert transform_result.count() == 3 dataset = transform_result.collect() # check field mapping assert dataset[0]['CUSTOMER_ID'] == '101' assert dataset[1]['CUSTOMER_ID'] == '102' assert dataset[2]['CUSTOMER_ID'] == '103' assert dataset[0]['YOUR_NAME'] == "customerName.one" assert dataset[0]['THE_OBJECTIVE'] == "customerBudget.one" assert dataset[0]['AD_ID'] == "tempId.one" assert dataset[0]['AD_NAME'] == "myName.one" assert dataset[0]['GEO_LOC'] == "geo_location.one" assert dataset[0]['ORDER_ID'] == "orderId.test" assert dataset[0]['ORDER_NAME'] == "orderName.test" assert dataset[0]['DT'] == "__time.one" assert dataset[0]['AUDIO_IMPRESSIONS'] == 1 assert transform_result.columns.__contains__('RUN_ID') assert transform_result.columns.__contains__('REPORT_START_DT') assert transform_result.columns.__contains__('REPORT_END_DT') assert transform_result.columns.__contains__('record_number') # check mocks were properly called mock_results[0].assert_called_once() mock_results[1].assert_called_once_with(f"https://custom.io/v1/async-query/REPORT_A", headers={'agency': '12', 'x-api-key': 'key', 'Content-Type': 'application/json'}) mock_results[2].assert_called_once_with("https://test.my.download", header=0, skip_blank_lines=True)
Decorators are available for all types of Ascend python implementation strategies. Testing scenarios are only limited by your creativity and desire to produce high quality code.
Download your pipelines using the Ascend CLI like this:
ascend download dataflow MY_DATASERVICE MY_DATA_FLOW
Write some tests. When your test cases are complete, pushing the code to the platform is simple with the CLI. For example:
ascend apply dataflow MY_DATASERVICE MY_DATA_FLOW
Read the Docs
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ascend_io_test-0.9.7.tar.gz
.
File metadata
- Download URL: ascend_io_test-0.9.7.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.8.18 Linux/5.15.0-1039-aws
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19241300dae92e9d204bd9f7e30292adb5f67cf153515cb21b27b6ff693be73d |
|
MD5 | 0cd1e081ec01816cb2cdaa85f35a26d4 |
|
BLAKE2b-256 | 32eae16cda3257c3c70616e54a19aba2b00a1c9543378266224e6c3c7214ffef |
File details
Details for the file ascend_io_test-0.9.7-py3-none-any.whl
.
File metadata
- Download URL: ascend_io_test-0.9.7-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.8.18 Linux/5.15.0-1039-aws
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fda7ebff8ee66d3d67a1eb815786d74c8d268c592c44d1a9ea40ffea15c70a18 |
|
MD5 | 41a90b8c940f49df8d25614f4a03187e |
|
BLAKE2b-256 | 13ac7bb9e467faef6b189fb4abedf9ae2f0a816799119160e8ce92745bbba4e2 |