-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_tests_logging.py
76 lines (62 loc) · 2.36 KB
/
write_tests_logging.py
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
import requests
import json
import sys
import datetime
import re
# Get the current date
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
def fetch_data(url):
print("Fetching data...")
try:
response = requests.get(url)
response.raise_for_status()
return response.json()
except requests.RequestException as e:
print(f"Error fetching data: {e}")
return None
def generate_test(prop, game_name, game_version):
print(f"Generating test for property {prop.get('path')}...")
path = prop.get('path')
address = prop.get('address')
bytes_value = prop.get('bytes')
bytes_str = f"[{', '.join(map(str, bytes_value))}]" if bytes_value else None
value = prop.get('value')
if path is not None:
# Replace any characters that are not letters, numbers, or underscores with underscores
sanitized_path = re.sub(r'\W', '_', path)
test_method = f"""
[TestMethod]
public async Task {sanitized_path}()
{{
await Load_{game_name}({game_version});
var mapper = await GameHookClient.GetMapperAsync();
"""
if address and bytes_value:
test_method += f'\n mapper.AssertAreEqual("{path}", 0x{address:X}, {bytes_str},'
elif value is not None:
test_method += f'\n mapper.AssertAreEqual("{path}",'
else:
return None
test_method += f' {json.dumps(value)});'
test_method += "\n }\n"
print(f"Generated test for property {prop.get('path')}")
return test_method
print(f"Failed to generate test for property {prop.get('path')}")
return None
# URL of the server
url = "http://localhost:8085/mapper"
# Fetch the data from the server
data = fetch_data(url)
# Get the game name and version from the command line arguments
game_name = sys.argv[1] if len(sys.argv) > 1 else "GB_PokemonYellow"
game_version = sys.argv[2] if len(sys.argv) > 2 else "0"
if data:
# Get the current date
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
# Open the file with the current date in the name
with open(f'tests/{game_name}_{game_version}_tests_{current_date}.txt', 'w') as f:
# Generate and write each test
for prop in data['properties']:
test = generate_test(prop, game_name, game_version)
if test:
f.write(test)