Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions burr/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,14 @@ def create_test_case(
if target_file_name:
# if it already exists, load it up and append to it
if os.path.exists(target_file_name):
with open(target_file_name, "r") as f:
with open(target_file_name, "r", encoding="utf-8") as f:
# assumes it's a list of test cases
current_testcases = json.load(f)
current_testcases.append(tc_json)
else:
current_testcases = [tc_json]
print(f"\nWriting data to file {target_file_name}")
with open(target_file_name, "w") as f:
with open(target_file_name, "w", encoding="utf-8") as f:
json.dump(current_testcases, f, indent=2)
else:
logger.info(json.dumps(tc_json, indent=2))
Expand Down
2 changes: 1 addition & 1 deletion burr/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# and then load it for the test.
def load_test_cases(file_name: str) -> tuple:
"""Load test cases from a json file."""
with open(file_name, "r") as f:
with open(file_name, "r", encoding="utf-8") as f:
json_test_cases = json.load(f)
test_cases = [(tc.get("input_state"), tc.get("expected_state")) for tc in json_test_cases]
test_ids = [
Expand Down
43 changes: 43 additions & 0 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import json

from burr.testing import load_test_cases


def test_load_test_cases_reads_utf8_json(tmp_path):
test_case_file = tmp_path / "test_cases.json"
test_case_file.write_text(
json.dumps(
[
{
"action": "summarize",
"name": "handles_utf8",
"input_state": {"message": "café"},
"expected_state": {"response": "résumé"},
}
],
ensure_ascii=False,
),
encoding="utf-8",
)

test_cases, test_ids = load_test_cases(str(test_case_file))

assert test_cases == [({"message": "café"}, {"response": "résumé"})]
assert test_ids == ["summarize-handles_utf8"]
Loading