Skip to content

Commit

Permalink
Merge branch 'main' into clwan/sample_1_10
Browse files Browse the repository at this point in the history
  • Loading branch information
YingChen1996 authored Apr 25, 2024
2 parents e92e536 + 7725069 commit de99a63
Show file tree
Hide file tree
Showing 57 changed files with 2,263 additions and 1,663 deletions.
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@
"mpnet",
"wargs",
"dcid",
"piezo",
"Piezo",
"cmpop"
],
"flagWords": [
"Prompt Flow"
],
"allowCompoundWords": true
}
}
36 changes: 36 additions & 0 deletions .github/workflows/promptflow-core-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ jobs:
- name: generate end-to-end test config from secret
run: echo '${{ secrets.PF_TRACING_E2E_TEST_CONFIG }}' >> connections.json
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: set test mode
run: |
echo "PROMPT_FLOW_TEST_MODE=$(if [[ "${{ github.event_name }}" == "pull_request" ]]; then echo replay; else echo live; fi)" >> $GITHUB_ENV
- name: Azure login (non pull_request workflow)
if: github.event_name != 'pull_request'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: generate live test resources (non pull_request workflow)
if: github.event_name != 'pull_request'
uses: "./.github/actions/step_generate_configs"
with:
targetFolder: ${{ env.PROMPTFLOW_DIRECTORY }}
- name: generate live test resources (pull_request workflow)
if: github.event_name == 'pull_request'
working-directory: ${{ env.PROMPTFLOW_DIRECTORY }}
run: |
cp ${{ github.workspace }}/src/promptflow/dev-connections.json.example ${{ github.workspace }}/src/promptflow/connections.json
- name: run core tests
run: poetry run pytest ./tests/core --cov=promptflow --cov-config=pyproject.toml --cov-report=term --cov-report=html --cov-report=xml
working-directory: ${{ env.WORKING_DIRECTORY }}
Expand Down Expand Up @@ -77,6 +95,24 @@ jobs:
poetry run pip show promptflow-tracing
poetry run pip show promptflow-core
working-directory: ${{ env.WORKING_DIRECTORY }}
- name: set test mode
run: |
echo "PROMPT_FLOW_TEST_MODE=$(if [[ "${{ github.event_name }}" == "pull_request" ]]; then echo replay; else echo live; fi)" >> $GITHUB_ENV
- name: Azure login (non pull_request workflow)
if: github.event_name != 'pull_request'
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: generate live test resources (non pull_request workflow)
if: github.event_name != 'pull_request'
uses: "./.github/actions/step_generate_configs"
with:
targetFolder: ${{ env.PROMPTFLOW_DIRECTORY }}
- name: generate live test resources (pull_request workflow)
if: github.event_name == 'pull_request'
working-directory: ${{ env.PROMPTFLOW_DIRECTORY }}
run: |
cp ${{ github.workspace }}/src/promptflow/dev-connections.json.example ${{ github.workspace }}/src/promptflow/connections.json
- name: run azureml-serving tests
run: poetry run pytest ./tests/azureml-serving --cov=promptflow --cov-config=pyproject.toml --cov-report=term --cov-report=html --cov-report=xml
working-directory: ${{ env.WORKING_DIRECTORY }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SummaryLine:
start_time: str = None
end_time: str = None
status: str = None
latency: float = 0.0
latency: float = None
name: str = None
kind: str = None
created_by: typing.Dict = field(default_factory=dict)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import json
import tempfile
from pathlib import Path

import mock
import pytest
from flask.app import Flask


@pytest.fixture
def app() -> Flask:
from promptflow._sdk._service.app import create_app

app, _ = create_app()
app.config.update({"TESTING": True})
yield app


@pytest.fixture
def pfs_op(app: Flask):
# Hack to import the pfs test utils from the devkit tests
import sys

sys.path.append("../promptflow-devkit/tests")
from sdk_pfs_test.utils import PFSOperations

client = app.test_client()
return PFSOperations(client)


@pytest.mark.e2etest
class TestPFSAzure:
@pytest.mark.skipif(pytest.is_replay, reason="connection provider test, skip in non-live mode.")
def test_get_connection_by_provider(self, pfs_op, subscription_id, resource_group_name, workspace_name):
target = "promptflow._sdk._pf_client.Configuration.get_connection_provider"
provider_url_target = "promptflow.core._utils.extract_workspace"
mock_provider_url = (subscription_id, resource_group_name, workspace_name)
with mock.patch(target) as mocked_config, mock.patch(provider_url_target) as mocked_provider_url:
mocked_config.return_value = "azureml"
mocked_provider_url.return_value = mock_provider_url
connections = pfs_op.list_connections(status_code=200).json
assert len(connections) > 0

connection = pfs_op.get_connection(name=connections[0]["name"], status_code=200).json
assert connection["name"] == connections[0]["name"]

target = "promptflow._sdk._pf_client.Configuration.get_config"
with tempfile.TemporaryDirectory() as temp:
config_file = Path(temp) / ".azureml" / "config.json"
config_file.parent.mkdir(parents=True, exist_ok=True)
with open(config_file, "w") as f:
config = {
"subscription_id": subscription_id,
"resource_group": resource_group_name,
"workspace_name": workspace_name,
}
json.dump(config, f)
with mock.patch(target) as mocked_config:
mocked_config.return_value = "azureml"
connections = pfs_op.list_connections_by_provider(working_dir=temp, status_code=200).json
assert len(connections) > 0

connection = pfs_op.get_connections_by_provider(
name=connections[0]["name"], working_dir=temp, status_code=200
).json
assert connection["name"] == connections[0]["name"]

# this test checked 2 cases:
# 1. if the working directory is not exist, it should return 400
# 2. working directory has been encoded and decoded correctly, so that previous call may pass validation
error_message = pfs_op.list_connections_by_provider(
working_dir=temp + "not exist", status_code=400
).json
assert error_message == {
"errors": {"working_directory": "Invalid working directory."},
"message": "Input payload validation failed",
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def _parse_entry_func(self):
if self.is_function_entry:
if inspect.isfunction(self._entry):
return self._entry
self._initialize_aggr_function(self._entry)
return self._entry.__call__
module_name, func_name = self._parse_flow_file()
try:
Expand Down
2 changes: 2 additions & 0 deletions src/promptflow-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ promptflow-recording = {path = "../promptflow-recording"}
pytest = "*"
pytest-cov = "*"
pytest-xdist = "*"
pytest-mock = "*"
mock = "*"

[build-system]
requires = [
Expand Down
Empty file.
Loading

0 comments on commit de99a63

Please sign in to comment.