|
8 | 8 | from sqlalchemy import create_engine, text |
9 | 9 |
|
10 | 10 | import openstatspec |
| 11 | +from conformance import compare_sav_semantics, write_supported_semantics_fixture |
11 | 12 |
|
12 | 13 |
|
13 | 14 | pytestmark = pytest.mark.services |
@@ -69,3 +70,48 @@ def test_live_profile_import_validate_and_export(environment_name, dataset_id, s |
69 | 70 | assert frame["name"].tolist() == ["Ada", ""] |
70 | 71 | assert metadata.column_labels == ["Age", "Name"] |
71 | 72 | assert metadata.variable_value_labels == {"age": {34.0: "thirty-four"}} |
| 73 | + |
| 74 | +@pytest.mark.parametrize( |
| 75 | + ("environment_name", "dataset_id"), |
| 76 | + [ |
| 77 | + ("OPENSTATSPEC_POSTGRES_URL", "semantics_pg"), |
| 78 | + ("OPENSTATSPEC_MYSQL_URL", "semantics_mysql"), |
| 79 | + ("OPENSTATSPEC_MARIADB_URL", "semantics_mariadb"), |
| 80 | + ], |
| 81 | +) |
| 82 | +@pytest.mark.parametrize("suffix", [".sav", ".zsav"]) |
| 83 | +def test_live_profile_preserves_supported_sav_semantics( |
| 84 | + environment_name, dataset_id, suffix, tmp_path, |
| 85 | +): |
| 86 | + """Exercise every supported SPSS semantic on each real SQL family. |
| 87 | +
|
| 88 | + The narrow contract has no alternate long-form fallback: every profile |
| 89 | + must preserve the exact wide table and supported dictionary metadata for |
| 90 | + both uncompressed SAV and compressed ZSAV inputs. |
| 91 | + """ |
| 92 | + database_url = os.environ.get(environment_name) |
| 93 | + if not database_url: |
| 94 | + pytest.skip(f"{environment_name} is not configured") |
| 95 | + |
| 96 | + source = tmp_path / f"{dataset_id}{suffix}" |
| 97 | + destination = tmp_path / f"{dataset_id}-roundtrip{suffix}" |
| 98 | + write_supported_semantics_fixture(source) |
| 99 | + |
| 100 | + imported = openstatspec.import_sav( |
| 101 | + source, database_url=database_url, dataset_id=f"{dataset_id}_{suffix[1:]}", |
| 102 | + ) |
| 103 | + assert imported["case_count"] == 4 |
| 104 | + assert openstatspec.validate( |
| 105 | + database_url=database_url, dataset_id=f"{dataset_id}_{suffix[1:]}", |
| 106 | + )["valid"] is True |
| 107 | + |
| 108 | + openstatspec.export_sav( |
| 109 | + database_url=database_url, |
| 110 | + dataset_id=f"{dataset_id}_{suffix[1:]}", |
| 111 | + destination=destination, |
| 112 | + allow_loss=["unobservable-source-dictionary-features"], |
| 113 | + ) |
| 114 | + assert compare_sav_semantics(source, destination) == { |
| 115 | + "equivalent": True, |
| 116 | + "differences": [], |
| 117 | + } |
0 commit comments