-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.py
More file actions
91 lines (69 loc) · 2.72 KB
/
integration_test.py
File metadata and controls
91 lines (69 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import logging
import sys
import time
import pandas as pd
import pytest
import main
from arena.arena import parse_stimulus_matrix, Sheet, run_sheets, collect_actuation_sheets, SheetInvocation, \
lql_to_sheet_signature
from arena.engine.adaptation import PassThroughAdaptationStrategy, \
SingleFunctionAdaptationStrategy
from arena.engine.artifacts import CodeCandidate, import_classes_under_test, write_modules_and_import_cuts
from arena.engine.classes import ClassUnderTest
from arena.engine.ssntestdriver import interpret_sheet, run_sheet, InvocationListener, Test, TestInvocation
from arena.lql.lqlparser import parse_lql
from arena.ssn.ssnparser import parse_sheet
# logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
def test_srm_base64_external_functions():
"""
Demonstrates typical scenario: SM as input and SRM as output (here functions are assumed)
:return:
"""
# lql (interface specification)
lql = """Base64 {
encode(str)->str
}
"""
# stimulus sheet
ssn_jsonl = """
{"cells": {"A1": "", "B1": "create", "C1": "Base64"}}
{"cells": {"A2": "", "B2": "encode", "C2": "A1", "D2": "'Hello World!'"}}
"""
code_solutions = ["""
import base64
def encode(string):
# Convert the string to bytes
string_bytes = string.encode('utf-8')
# Encode the bytes into Base64
base64_encoded = base64.b64encode(string_bytes)
# Decode the bytes back into a string
base64_string = base64_encoded.decode('utf-8')
return base64_string
"""]
# classes under test
target_folder = f"/tmp/arena-python-{round(time.time() * 1000)}"
cuts = write_modules_and_import_cuts(target_folder, code_solutions)
# create stimulus matrix
sm = parse_stimulus_matrix([Sheet("test1()", ssn_jsonl, lql)], cuts, [SheetInvocation("test1", "")])
logger.debug(sm.to_string())
assert len(sm.columns) == 1
assert len(sm.index) == 1
# run stimulus matrix
invocation_listener = InvocationListener()
srm = run_sheets(sm, 1, invocation_listener, measure_code_coverage=True)
# results based on internal ExecutedInvocation
logger.debug(srm.to_string())
assert len(srm.columns) == 1
assert len(srm.index) == 1
# create actuation sheets, now we have the real stimulus response matrix (SRM)
srm_actuations = collect_actuation_sheets(srm)
logger.debug(srm_actuations.to_string())
assert len(srm_actuations.columns) == 1
assert len(srm_actuations.index) == 1