MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / test_history_from_json

Function test_history_from_json

tests/test_history.py:337–362  ·  view source on GitHub ↗
(hist)

Source from the content-addressed store, hash-verified

335
336
337def test_history_from_json(hist) -> None:
338 import json
339
340 from cmd2.history import (
341 History,
342 )
343
344 assert hist.from_json(hist_json) == hist
345
346 # Test invalid JSON
347 with pytest.raises(json.JSONDecodeError):
348 hist.from_json("")
349
350 # Send JSON with missing required element
351 with pytest.raises(KeyError):
352 hist.from_json("{}")
353
354 # Create JSON with invalid history version
355 backed_up_ver = History._history_version
356 History._history_version = "BAD_VERSION"
357 invalid_ver_json = hist.to_json()
358 History._history_version = backed_up_ver
359
360 expected_err = f"Unsupported history file version: BAD_VERSION. This application uses version {History._history_version}."
361 with pytest.raises(ValueError, match=expected_err):
362 hist.from_json(invalid_ver_json)
363
364
365#

Callers

nothing calls this directly

Calls 2

from_jsonMethod · 0.80
to_jsonMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…