-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_classifier.py
More file actions
42 lines (33 loc) · 1.33 KB
/
Copy pathtest_classifier.py
File metadata and controls
42 lines (33 loc) · 1.33 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
import csv
import os
from isic_classifier import classify_file, classify_chatgpt, load_isic, openai
from isic_classifier import classify_file
def test_classify_file(tmp_path):
input_csv = os.path.join(tmp_path, 'input.csv')
output_csv = os.path.join(tmp_path, 'output.csv')
# copy sample activities file
with open('sample_activities.csv', 'r', encoding='utf-8') as src:
data = src.read()
with open(input_csv, 'w', encoding='utf-8') as dst:
dst.write(data)
classify_file(input_csv, output_csv)
with open(output_csv, newline='', encoding='utf-8') as f:
reader = csv.DictReader(f)
results = list(reader)
codes = [row['isic_code'] for row in results]
assert codes[0] == '0112'
assert codes[1] == '6201'
assert codes[2] == '5610'
assert codes[3] == '5510'
assert codes[4] == '9311'
def test_classify_chatgpt(monkeypatch):
calls = {}
def fake_create(model, messages, temperature=0):
calls['model'] = model
calls['messages'] = messages
return {"choices": [{"message": {"content": "6201"}}]}
monkeypatch.setattr(openai.ChatCompletion, "create", fake_create)
isic_data = load_isic()
code = classify_chatgpt("Custom software development services", isic_data)
assert code == "6201"
assert calls.get('model') == "gpt-3.5-turbo"