From 9b9e629548641601bbbac276ddf70b2df7b348d2 Mon Sep 17 00:00:00 2001 From: Andrei Stoica Date: Sat, 15 Oct 2022 13:17:23 -0400 Subject: [PATCH] added test for loading json file --- test/test_insert_sites.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test_insert_sites.py b/test/test_insert_sites.py index a792f5f..cba9585 100644 --- a/test/test_insert_sites.py +++ b/test/test_insert_sites.py @@ -1,7 +1,28 @@ import inspect +import json +import os from recipe_graph import insert_sites from sqlalchemy import select from sqlalchemy.exc import SQLAlchemyError import sqlalchemy import pytest + + +@pytest.fixture +def json_data() -> list[dict]: + return [{"key": "value"}, {"test": "value1", "test2": "value2"}] + + +@pytest.fixture +def json_file(json_data: list[dict]) -> str: + f_path = "test.json" + with open(f_path, 'w') as f: + json.dump(json_data, f) + yield f_path + if os.path.exists(f_path): + os.remove(f_path) + +def test_load_file(json_file: str, json_data): + test_data = insert_sites.load_file(json_file) + assert test_data == json_data \ No newline at end of file