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

SMTorg / smt-optim / 28806559135

06 Jul 2026 04:23PM UTC coverage: 87.169% (+0.6%) from 86.529%
28806559135

push

github

web-flow
  Fix: Resolve RSCV constraint bug, correct variance margins for relaxation, and fix CI Coveralls (#21)

109 of 110 new or added lines in 4 files covered. (99.09%)

360 existing lines in 43 files now uncovered.

3757 of 4310 relevant lines covered (87.17%)

1.74 hits per line

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

98.61
/src/tests/test_unit/test_json.py
1
import unittest
2✔
2
import numpy as np
2✔
3
import warnings
2✔
4
import json
2✔
5

6
# Adjust this import to your actual module
7
from smt_optim.utils.json import json_safe
2✔
8

9

10
class TestJsonSafe(unittest.TestCase):
2✔
11

12
    # test primitives
13
    def test_none(self):
2✔
14
        self.assertIsNone(json_safe(None))
2✔
15

16
    def test_primitives(self):
2✔
17
        self.assertEqual(json_safe(True), True)
2✔
18
        self.assertEqual(json_safe(5), 5)
2✔
19
        self.assertEqual(json_safe(3.14), 3.14)
2✔
20
        self.assertEqual(json_safe("hello"), "hello")
2✔
21

22

23
    # numpy scalars
24
    def test_numpy_integer(self):
2✔
25
        x = np.int64(42)
2✔
26
        result = json_safe(x)
2✔
27
        self.assertEqual(result, 42)
2✔
28
        self.assertIsInstance(result, int)
2✔
29

30
    def test_numpy_floating(self):
2✔
31
        x = np.float64(2.5)
2✔
32
        result = json_safe(x)
2✔
33
        self.assertEqual(result, 2.5)
2✔
34
        self.assertIsInstance(result, float)
2✔
35

36

37
    # numpy array
38
    def test_numpy_array(self):
2✔
39
        arr = np.array([1, 2, 3])
2✔
40
        self.assertEqual(json_safe(arr), [1, 2, 3])
2✔
41

42

43
    # dictionary
44
    def test_dict_simple(self):
2✔
45
        d = {"a": 1, "b": np.int64(3)}
2✔
46
        result = json_safe(d)
2✔
47
        self.assertEqual(result, {"a": 1, "b": 3})
2✔
48

49
    def test_dict_key_string_conversion(self):
2✔
50
        d = {1: "a", 2.5: "b"}
2✔
51
        result = json_safe(d)
2✔
52
        self.assertEqual(result, {"1": "a", "2.5": "b"})
2✔
53

54
    def test_dict_with_unserializable_value(self):
2✔
55
        class Bad:
2✔
56
            def __repr__(self):
2✔
57
                return "BadObject"
2✔
58

59
        d = {"a": Bad()}
2✔
60
        result = json_safe(d)
2✔
61
        self.assertEqual(result, {"a": None})
2✔
62

63

64
    # list and tuple
65
    def test_list(self):
2✔
66
        data = [1, np.int64(2), np.array([3, 4])]
2✔
67
        result = json_safe(data)
2✔
68
        self.assertEqual(result, [1, 2, [3, 4]])
2✔
69

70
    def test_tuple(self):
2✔
71
        data = (1, np.float64(2.5))
2✔
72
        result = json_safe(data)
2✔
73
        self.assertEqual(result, [1, 2.5])  # tuple becomes list
2✔
74

75
    def test_list_with_unserializable(self):
2✔
76
        class Bad:
2✔
77
            pass
2✔
78

79
        data = [1, Bad()]
2✔
80
        result = json_safe(data)
2✔
81
        self.assertEqual(result, [1, None])
2✔
82

83

84
    # already JSON serializable
85
    def test_json_serializable_object(self):
2✔
86
        data = {"x": 1, "y": [1, 2]}
2✔
87
        result = json_safe(data)
2✔
88
        self.assertEqual(result, data)
2✔
89

90

91
    # outer exception handling
92
    def test_outer_exception_returns_none_and_warns(self):
2✔
93
        class Exploding:
2✔
94
            def __repr__(self):
2✔
95
                raise RuntimeError("Boom")
2✔
96

97
        obj = Exploding()
2✔
98

99
        with warnings.catch_warnings(record=True) as w:
2✔
100
            warnings.simplefilter("always")
2✔
101
            result = json_safe(obj)
2✔
102

103
            self.assertIsNone(result)
2✔
104
            self.assertTrue(len(w) > 0)
2✔
105
            self.assertTrue("Failed to convert" in str(w[0].message))
2✔
106

107

108
if __name__ == "__main__":
2✔
UNCOV
109
    unittest.main()
×
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