test_generic_filament_ids.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """One table of generic Bambu filament ids, complete for every generic Bambu has.
  2. A PP spool without a preset was sent to the printer with tray_info_idx=""
  3. because the shared table had no PP row, while the Configure dialog's own copy
  4. did (#3273). The copies are gone; these tests keep the table complete.
  5. """
  6. from __future__ import annotations
  7. import pytest
  8. from backend.app.api.routes import printers
  9. from backend.app.api.routes.cloud import _BUILTIN_FILAMENT_NAMES
  10. from backend.app.utils.filament_ids import (
  11. GENERIC_FILAMENT_IDS,
  12. GENERIC_IDS_REPLACED_ON_REUSE,
  13. filament_id_to_setting_id,
  14. normalize_slicer_filament,
  15. setting_id_to_filament_id,
  16. )
  17. from backend.app.utils.filament_types import is_material_name
  18. @pytest.mark.parametrize(
  19. "material,expected",
  20. [
  21. ("PP", "GFP97"),
  22. ("PE", "GFP99"),
  23. ("PCTG", "GFG97"),
  24. ("PLA SILK", "GFL96"),
  25. ("PLA HIGH SPEED", "GFL95"),
  26. ],
  27. )
  28. def test_the_materials_that_were_missing_have_their_generic(material, expected):
  29. assert GENERIC_FILAMENT_IDS[material] == expected
  30. def test_every_id_is_a_bambu_generic_preset():
  31. for material, filament_id in GENERIC_FILAMENT_IDS.items():
  32. name = _BUILTIN_FILAMENT_NAMES.get(filament_id, "")
  33. assert name.startswith("Generic "), f"{material} -> {filament_id} is not a generic preset ({name!r})"
  34. assert filament_id_to_setting_id(filament_id) == "GFS" + filament_id[2:]
  35. def test_the_reuse_check_replaces_exactly_the_generics_it_always_has():
  36. """The table grew; what slot reuse replaces must not have grown with it."""
  37. added = {"GFL96", "GFL95", "GFG97", "GFP99", "GFP97"}
  38. assert set(GENERIC_FILAMENT_IDS.values()) - added == GENERIC_IDS_REPLACED_ON_REUSE
  39. assert not hasattr(printers, "_GENERIC_ID_VALUES")
  40. def test_the_configure_route_keeps_no_copy_of_its_own():
  41. assert not hasattr(printers, "_ORCA_GENERIC_IDS")
  42. assert printers._orca_generic_filament_id("PP") == "GFP97"
  43. assert printers._orca_generic_filament_id("PLA Silk") == "GFL96"
  44. @pytest.mark.parametrize("material", ["PP", "PE", "PCTG"])
  45. def test_a_material_with_a_generic_is_a_material_name_not_a_preset_id(material):
  46. """So the resolver discards it as a preset and the generic rescues the slot."""
  47. assert is_material_name(material)
  48. @pytest.mark.parametrize(
  49. "filament_id,setting_id",
  50. [
  51. ("GFS99", "GFSS99"), # Generic PVA
  52. ("GFS98", "GFSS98"), # Generic HIPS
  53. ("GFS00", "GFSS00"), # Bambu Support W
  54. ("GFL05", "GFSL05"),
  55. ],
  56. )
  57. def test_support_filaments_convert_both_ways(filament_id, setting_id):
  58. """Support filaments are family S, so their filament_id starts with "GFS"
  59. too. Read as a setting_id, Generic PVA went out as setting_id "GFS99" and
  60. came back as filament_id "GF99"; Bambu's own profile says GFSS99."""
  61. assert filament_id_to_setting_id(filament_id) == setting_id
  62. assert filament_id_to_setting_id(setting_id) == setting_id
  63. assert setting_id_to_filament_id(setting_id) == filament_id
  64. assert setting_id_to_filament_id(filament_id) == filament_id
  65. assert normalize_slicer_filament(filament_id) == (filament_id, setting_id)
  66. assert normalize_slicer_filament(setting_id + "_07") == (filament_id, setting_id)