|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Issue 3 — `SqliteMerger` rejects non-SQLite source databases. |
| 4 | +
|
| 5 | +`SqliteUCIS.merge(source)` delegates to `SqliteMerger`, which accesses |
| 6 | +`scope.scope_id` on the source. When the source is a `MemUCIS`, its |
| 7 | +scopes are `MemScope` objects that lack `scope_id`, causing: |
| 8 | +
|
| 9 | + AttributeError: 'MemScope' object has no attribute 'scope_id' |
| 10 | +
|
| 11 | +This prevents merging XML/YAML-loaded (in-memory) databases into SQLite. |
| 12 | +
|
| 13 | +Reproduce: |
| 14 | + python test_issue_reproduce.py |
| 15 | +
|
| 16 | +Expected: SqliteUCIS.merge(mem_db) merges coverage data successfully. |
| 17 | +Actual: AttributeError is raised. |
| 18 | +""" |
| 19 | + |
| 20 | +import os |
| 21 | +import sys |
| 22 | +import tempfile |
| 23 | +import traceback |
| 24 | + |
| 25 | + |
| 26 | +def create_sample_mem_db(): |
| 27 | + """Return a small MemUCIS with one covergroup/coverpoint/bin.""" |
| 28 | + from ucis.mem.mem_ucis import MemUCIS |
| 29 | + from ucis.source_info import SourceInfo |
| 30 | + from ucis.source_t import SourceT |
| 31 | + from ucis.scope_type_t import ScopeTypeT |
| 32 | + from ucis.cover_data import CoverData |
| 33 | + from ucis.cover_type_t import CoverTypeT |
| 34 | + from ucis.flags_t import FlagsT |
| 35 | + |
| 36 | + db = MemUCIS() |
| 37 | + fh = db.createFileHandle("test.sv", os.getcwd()) |
| 38 | + si = SourceInfo(fh, 1, 0) |
| 39 | + du = db.createScope("tb", si, 1, SourceT.NONE, ScopeTypeT.DU_MODULE, FlagsT(0)) |
| 40 | + inst = db.createInstance("tb", si, 1, SourceT.NONE, |
| 41 | + ScopeTypeT.INSTANCE, du, FlagsT(0)) |
| 42 | + cg = inst.createCovergroup("cg", si, 1, SourceT.NONE) |
| 43 | + cp = cg.createScope("cp", si, 1, SourceT.NONE, ScopeTypeT.COVERPOINT, FlagsT(0)) |
| 44 | + cd = CoverData(CoverTypeT.CVGBIN, 0) |
| 45 | + cd.data = 10 |
| 46 | + cp.createNextCover("bin0", cd, si) |
| 47 | + return db |
| 48 | + |
| 49 | + |
| 50 | +def test_sqlite_merge_from_mem(): |
| 51 | + """SqliteUCIS.merge(MemUCIS) should succeed.""" |
| 52 | + from ucis.sqlite.sqlite_ucis import SqliteUCIS |
| 53 | + |
| 54 | + src = create_sample_mem_db() |
| 55 | + |
| 56 | + with tempfile.NamedTemporaryFile(suffix=".ucisdb", delete=False) as f: |
| 57 | + dst_path = f.name |
| 58 | + |
| 59 | + try: |
| 60 | + dst = SqliteUCIS(dst_path) |
| 61 | + dst.merge(src) |
| 62 | + dst.close() |
| 63 | + print("PASS — SqliteUCIS.merge(MemUCIS) succeeded") |
| 64 | + return True |
| 65 | + except AttributeError as exc: |
| 66 | + if "scope_id" in str(exc): |
| 67 | + print("FAIL — Issue 3 reproduced:") |
| 68 | + traceback.print_exc() |
| 69 | + return False |
| 70 | + raise |
| 71 | + except Exception as exc: |
| 72 | + if "scope_id" in str(exc): |
| 73 | + print("FAIL — Issue 3 reproduced:") |
| 74 | + traceback.print_exc() |
| 75 | + return False |
| 76 | + raise |
| 77 | + finally: |
| 78 | + if os.path.exists(dst_path): |
| 79 | + os.remove(dst_path) |
| 80 | + |
| 81 | + |
| 82 | +if __name__ == "__main__": |
| 83 | + ok = test_sqlite_merge_from_mem() |
| 84 | + sys.exit(0 if ok else 1) |
0 commit comments