Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Create Test Cases Directory if not Exists
Browse files Browse the repository at this point in the history
Make test cases paths relative to script path.
  • Loading branch information
EmteZogaf committed May 26, 2021
1 parent b3bf276 commit b05b332
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import json, os
from testDataToUnitTest import generate_unit_test

if __name__ == '__main__':
with open(f"testData.json", encoding="utf-8") as json_file:
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "testData.json"), encoding = "utf-8") as json_file:
test_data = json.load(json_file)
generate_unit_test(test_data)
14 changes: 10 additions & 4 deletions testDataToUnitTest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import os
from StructuredQuery import *

mapped_term_codes = []

with open("TermCodeMapping.json") as mapping_file:
scriptDir = os.path.dirname(os.path.realpath(__file__))
testCasesDir = os.path.join(scriptDir, "testCases")

with open(os.path.join(scriptDir, "TermCodeMapping.json")) as mapping_file:
mapping_json = json.load(mapping_file)
for mapping in mapping_json:
mapped_term_codes.append(TermCode(**mapping['key']))


def generate_unit_test(bundle):
os.makedirs(testCasesDir, exist_ok = True)

for entry in bundle["entry"]:
resource = entry["resource"]
resource_type = resource["resourceType"]
Expand Down Expand Up @@ -46,11 +52,11 @@ def generate_unit_test(bundle):
write_sq_to_file(sq, resource)


def write_sq_to_file(structured_query, resource, file_name=None):
def write_sq_to_file(structured_query, resource, file_name = None):
if file_name:
file = open("testCases/" + file_name + ".json", 'w')
file = open(os.path.join(testCasesDir, file_name + ".json"), 'w')
else:
file = open("testCases/" + resource["identifier"][0]["value"].split(".")[-1] + ".json", 'w')
file = open(os.path.join(testCasesDir, resource["identifier"][0]["value"].split(".")[-1] + ".json"), 'w')
file.write(structured_query.to_json())
file.close()

Expand Down

0 comments on commit b05b332

Please sign in to comment.