• 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.11
/src/tests/test_unit/test_json_logging.py
1
import os
2✔
2
import json
2✔
3
import unittest
2✔
4
import tempfile
2✔
5
from unittest.mock import patch
2✔
6

7

8
# --- Dummy state ---
9
class DummyState:
2✔
10
    def __init__(self):
2✔
11
        self.iter_log = {
2✔
12
            "a": 1,
13
            "b": 2.5
14
        }
15

16

17
class DummyConfig:
2✔
18
    def __init__(self, results_dir):
2✔
19
        self.results_dir = results_dir
2✔
20

21

22
# --- Tests ---
23
class TestJsonLogger(unittest.TestCase):
2✔
24

25
    def setUp(self):
2✔
26
        from smt_optim.utils.logger import JsonLogger
2✔
27

28
        self.tmpdir = tempfile.TemporaryDirectory()
2✔
29
        self.config = DummyConfig(self.tmpdir.name)
2✔
30
        self.logger = JsonLogger(self.config)
2✔
31
        self.state = DummyState()
2✔
32

33
    def tearDown(self):
2✔
34
        self.tmpdir.cleanup()
2✔
35

36
    def _get_log_path(self):
2✔
37
        return os.path.join(self.tmpdir.name, "stats.jsonl")
2✔
38

39
    def test_file_created_and_written(self):
2✔
40
        self.logger.on_iter_end(self.state)
2✔
41

42
        path = self._get_log_path()
2✔
43
        self.assertTrue(os.path.exists(path))
2✔
44

45
        with open(path, "r") as f:
2✔
46
            content = f.read()
2✔
47

48
        self.assertIn('"a": 1', content)
2✔
49
        self.assertIn('"b": 2.5', content)
2✔
50

51
    def test_appends_not_overwrites(self):
2✔
52
        self.logger.on_iter_end(self.state)
2✔
53
        self.logger.on_iter_end(self.state)
2✔
54

55
        path = self._get_log_path()
2✔
56

57
        with open(path, "r") as f:
2✔
58
            content = f.read()
2✔
59

60
        # Expect duplicated content
61
        self.assertGreater(len(content), 0)
2✔
62

63
        # crude but effective: key appears twice
64
        self.assertGreaterEqual(content.count('"a": 1'), 2)
2✔
65

66
    @patch("smt_optim.utils.json.json_safe")
2✔
67
    def test_json_safe_is_called(self, mock_json_safe):
2✔
68
        mock_json_safe.return_value = {"safe": True}
2✔
69

70
        self.logger.on_iter_end(self.state)
2✔
71

72
        self.assertGreaterEqual(mock_json_safe.call_count, 1)
2✔
73

74
        path = self._get_log_path()
2✔
75
        with open(path, "r") as f:
2✔
76
            content = f.read()
2✔
77

78
        self.assertIn('"safe": true', content)
2✔
79

80
    def test_directory_created(self):
2✔
81
        # Remove directory manually
82
        os.rmdir(self.tmpdir.name)
2✔
83

84
        self.logger.on_iter_end(self.state)
2✔
85

86
        self.assertTrue(os.path.exists(self.tmpdir.name))
2✔
87

88

89
if __name__ == "__main__":
2✔
UNCOV
90
    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