test_ams_slot_presence.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Unit tests for the firmware presence bit helper.
  2. #3084: a slot can read ``exists=True, state=9`` — the bit says a spool is in
  3. it, the state says the opposite — because ``apply_tray_exist_bits`` writes the
  4. 9 itself and never takes it back. Everything downstream has to know which of
  5. the two to believe, and this helper is the single place that says so.
  6. """
  7. from backend.app.services.ams_slot_presence import spool_present
  8. class TestSpoolPresent:
  9. def test_the_bit_is_reported_as_it_stands(self):
  10. assert spool_present({"id": 0, "exists": True}) is True
  11. assert spool_present({"id": 0, "exists": False}) is False
  12. def test_the_bit_answers_over_a_contradicting_state(self):
  13. # The #3084 slot: non-Bambu spool swapped in, so the bit is set, while
  14. # the 9 Bambuddy stamped on the slot when it was briefly empty is still
  15. # sitting there.
  16. assert spool_present({"id": 0, "exists": True, "state": 9}) is True
  17. # And the converse — a spool pulled from a slot the firmware last
  18. # described as loaded.
  19. assert spool_present({"id": 0, "exists": False, "state": 11}) is False
  20. def test_a_tray_with_no_annotation_answers_nothing(self):
  21. # vt_tray entries and the VP bridge's cache carry no presence bit, so
  22. # callers have to fall back to their own reading rather than be handed
  23. # a guess dressed up as firmware's answer.
  24. assert spool_present({"id": 0, "state": 11, "tray_type": "PLA"}) is None
  25. assert spool_present({}) is None
  26. def test_a_non_bool_exists_is_not_a_presence_bit(self):
  27. # Only apply_tray_exist_bits writes this key, and it writes a bool.
  28. # Anything else reached the dict some other way and is not firmware's
  29. # answer — 0 and "" would otherwise read as a confident "empty".
  30. assert spool_present({"exists": 0}) is None
  31. assert spool_present({"exists": ""}) is None
  32. assert spool_present({"exists": "true"}) is None
  33. assert spool_present({"exists": None}) is None
  34. def test_a_missing_tray_answers_nothing(self):
  35. assert spool_present(None) is None
  36. assert spool_present([]) is None
  37. assert spool_present("tray") is None