diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7259e5159f6..f7fa1e299ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.16.3 + rev: v0.16.2 hooks: - id: ruff-check types_or: [python, pyi, jupyter, toml] diff --git a/docs/examples/DataSet/Working with snapshots.ipynb b/docs/examples/DataSet/Working with snapshots.ipynb index 01ee99d42e3..49d42c62d4e 100644 --- a/docs/examples/DataSet/Working with snapshots.ipynb +++ b/docs/examples/DataSet/Working with snapshots.ipynb @@ -28,8 +28,9 @@ "outputs": [], "source": [ "import json # for converting JSON data into python 'dict'\n", + "from difflib import unified_diff\n", "from pathlib import Path\n", - "from pprint import pprint # for pretty-printing python variables like 'dict'\n", + "from pprint import pformat, pprint # for pretty-printing python variables like 'dict'\n", "\n", "from qcodes.dataset import (\n", " Measurement,\n", @@ -554,6 +555,8 @@ "metadata": {}, "outputs": [], "source": [ + "snapshot_of_station_before_run = station.snapshot()\n", + "\n", "with measurement.run() as data_saver:\n", " input_value = 111\n", " instr.input.set(input_value)\n", @@ -793,7 +796,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Note that the snapshot that we have just loaded from the dataset is almost the same as the snapshot that we directly obtained from the station above. One difference is that the snapshot loaded from the dataset has a top-level `station` field. It also has a top-level `parameters` field. If you do not trust me, have a look at the following `assert` statement for the proof." + "Note that the snapshot that we have just loaded from the dataset is almost the same as the snapshot that we directly obtained from the station immediately before the run. One difference is that the snapshot loaded from the dataset has a top-level `station` field. It also has a top-level `parameters` field. The following comparison raises an error with a unified diff if the station snapshots do not match." ] }, { @@ -802,7 +805,17 @@ "metadata": {}, "outputs": [], "source": [ - "assert snapshot_of_station == snapshot_of_run[\"station\"]" + "if snapshot_of_station_before_run != snapshot_of_run[\"station\"]:\n", + " snapshot_diff = \"\\n\".join(\n", + " unified_diff(\n", + " pformat(snapshot_of_station_before_run).splitlines(),\n", + " pformat(snapshot_of_run[\"station\"]).splitlines(),\n", + " fromfile=\"snapshot_of_station_before_run\",\n", + " tofile='snapshot_of_run[\"station\"]',\n", + " lineterm=\"\",\n", + " )\n", + " )\n", + " raise RuntimeError(f\"Station snapshots differ:\\n{snapshot_diff}\")" ] }, {