test_console_writer.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import pytest
  4. from draugr.writers import ConsoleWriter
  5. __author__ = "Christian Heider Nielsen"
  6. __doc__ = r"""
  7. """
  8. @pytest.mark.parametrize(
  9. ["tag", "val", "step"],
  10. (("signal", 0, 0), ("signal", 20, 1), ("signal", -1, 6)),
  11. ids=["signal_first", "signal_second", "signal_sixth"],
  12. )
  13. def test_valid_scalars(tag, val, step):
  14. with ConsoleWriter() as w:
  15. w.scalar(tag, val, step)
  16. @pytest.mark.parametrize(
  17. ["tag", "val", "step"],
  18. (("signal", "", 0), ("signal", None, 1), ("signal", object(), 6)),
  19. ids=["str_scalar", "None_scalar", "object_scalar"],
  20. )
  21. def test_invalid_val_type_scalars(tag, val, step):
  22. try:
  23. with ConsoleWriter() as w:
  24. w.scalar(tag, val, step)
  25. assert False
  26. except Exception as e:
  27. assert True
  28. @pytest.mark.parametrize(
  29. ["tag", "val", "step"],
  30. ((1, 0, 0), (None, 20, 1), (object(), -1, 6)),
  31. ids=["numeral_tag", "None_tag", "object_tag"],
  32. )
  33. def test_invalid_tag_scalars(tag, val, step):
  34. try:
  35. with ConsoleWriter() as w:
  36. w.scalar(tag, val, step)
  37. assert False
  38. except Exception as e:
  39. print(e)
  40. assert True
  41. @pytest.mark.parametrize(
  42. ["tag", "val", "step"],
  43. (("signal", 0, ""), ("signal", 20, None), ("tag1", -0, object())),
  44. ids=["str_step", "None_step", "object_step"],
  45. )
  46. def test_invalid_step_type_scalars(tag, val, step):
  47. try:
  48. with ConsoleWriter() as w:
  49. w.scalar(tag, val, step)
  50. assert False
  51. except Exception as e:
  52. print(e)
  53. assert True