• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / team4-wed-fall25 / 9

22 Oct 2025 08:01PM UTC coverage: 48.812%. First build
9

api

travis-pro

web-flow
Merge pull request #51 from gcivil-nyu-org/develop

Syncing main with develop branch

15 of 77 new or added lines in 5 files covered. (19.48%)

226 of 463 relevant lines covered (48.81%)

0.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.94
/note2webapp/utils.py
1
import importlib.util
1✔
2
import traceback
1✔
3
import json
1✔
4
import os
1✔
5

6
TYPE_MAP = {"float": float, "int": int, "str": str, "bool": bool}
1✔
7

8

9
def generate_dummy_input(schema_path):
1✔
10
    with open(schema_path, "r") as f:
1✔
11
        schema = json.load(f)
1✔
12

13
    input_schema = schema.get("input", {})
1✔
14
    dummy = {}
1✔
15
    for key, typ in input_schema.items():
1✔
16
        py_type = TYPE_MAP.get(typ)
1✔
17
        if py_type == float:
1✔
18
            dummy[key] = 1.0
1✔
19
        elif py_type == int:
1✔
20
            dummy[key] = 42
1✔
21
        elif py_type == str:
1✔
22
            dummy[key] = "example"
1✔
23
        elif py_type == bool:
1✔
24
            dummy[key] = True
1✔
25
        else:
26
            raise ValueError(f"Unsupported type: {typ}")
1✔
27
    return dummy, schema.get("output", {})
1✔
28

29

30
def validate_model(version):
1✔
31
    try:
×
32
        # 🔁 Change to directory containing model.pt
33
        model_dir = os.path.dirname(version.model_file.path)
×
34
        os.chdir(model_dir)
×
35

36
        # ✅ Dynamically import predict.py
NEW
37
        spec = importlib.util.spec_from_file_location(
×
38
            "predict", version.predict_file.path
39
        )
40
        module = importlib.util.module_from_spec(spec)
×
41
        spec.loader.exec_module(module)
×
42

43
        if not hasattr(module, "predict"):
×
44
            raise Exception("predict() function missing in predict.py")
×
45

46
        # Load schema + generate dummy input
47
        if not version.schema_file:
×
48
            raise Exception("No schema file provided")
×
49
        dummy_input, expected_output = generate_dummy_input(version.schema_file.path)
×
50

51
        # Call predict with ONLY dummy input
52
        output = module.predict(dummy_input)
×
53

54
        # Validate output
55
        if not isinstance(output, dict):
×
56
            raise Exception("predict() must return a dict")
×
57

58
        for key, typ in expected_output.items():
×
59
            if key not in output:
×
60
                raise Exception(f"Missing key in output: {key}")
×
61
            if not isinstance(output[key], TYPE_MAP.get(typ)):
×
NEW
62
                raise Exception(
×
63
                    f"Wrong type for '{key}': expected {typ}, got {type(output[key]).__name__}"
64
                )
65

66
        version.status = "PASS"
×
67
        version.log = f"Validation successful ✅\nInput: {json.dumps(dummy_input)}\nOutput: {json.dumps(output, indent=2)}"
×
68

69
    except Exception:
×
70
        version.status = "FAIL"
×
71
        version.log = traceback.format_exc()
×
72

73
    version.save()
×
74
    return version
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc