def test_save_and_load_when_test_name_with_quotes(self, tmpdir): filepath = tmpdir.join("snap_error.py") module = SnapshotModule("tests.snapshots.snap_error", str(filepath)) module["quo'tes"] = "result" module.save() loaded = module.load_snapshots() assert loaded["quo'tes"] == "result"
def try_add_snapshot(self): try: from snapshottest.module import SnapshotModule return { 'successful': SnapshotModule.stats_successful_snapshots(), 'failed': SnapshotModule.stats_failed_snapshots()[0], 'added': SnapshotModule.stats_new_snapshots()[0], 'matched': SnapshotModule.stats_visited_snapshots()[0], 'unmatched': SnapshotModule.stats_unvisited_snapshots()[0], } except ImportError: return {}
def fixture_snapshot_test(tmpdir): filepath = tmpdir.join("snap_mocked.py") module = SnapshotModule("tests.snapshots.snap_mocked", str(filepath)) return GenericSnapshotTest(module)
def test_load_not_yet_saved(self, tmpdir): filepath = tmpdir.join("snap_new.py") assert not filepath.check() # file does not exist module = SnapshotModule("tests.snapshots.snap_new", str(filepath)) snapshots = module.load_snapshots() assert isinstance(snapshots, Snapshot)
def test_load_corrupted_snapshot(self, tmpdir): filepath = tmpdir.join("snap_error.py") filepath.write_text("<syntax error>\n", "utf-8") module = SnapshotModule("tests.snapshots.snap_error", str(filepath)) with pytest.raises(SyntaxError): module.load_snapshots()
def test_load_missing_package(self, tmpdir): filepath = tmpdir.join("snap_import.py") filepath.write_text("import missing_package\n", "utf-8") module = SnapshotModule("tests.snapshots.snap_import", str(filepath)) with pytest.raises(ImportError): module.load_snapshots()
def snapshot_module(tmpdir): filepath = tmpdir.join("snap_mocked.py") module = SnapshotModule("tests.snapshots.snap_mocked", str(filepath)) return module
def module(filepath): return SnapshotModule("tests.snapshots.snapshot_module", str(filepath))