_list_test.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from unittest.mock import patch
  2. import pytest
  3. from yamily._cli import _list
  4. @patch("sys.argv", ["", "non/existing/file.yml"])
  5. def test__read_non_existing():
  6. with pytest.raises(FileNotFoundError):
  7. _list()
  8. @patch("sys.argv", ["", "persons/erika-mustermann.yml"])
  9. def test__list_single_simple(capsys):
  10. _list()
  11. out, err = capsys.readouterr()
  12. assert not err
  13. assert out == (
  14. "- !person\n"
  15. " birth_date: 1957-08-12\n"
  16. " identifier: erika-mustermann\n"
  17. " name: Erika Mustermann\n"
  18. )
  19. @patch("sys.argv", ["", "persons/max-mustermann.yml"])
  20. def test__list_single_parents(capsys):
  21. _list()
  22. out, err = capsys.readouterr()
  23. assert not err
  24. assert out == (
  25. "- &id001 !person\n"
  26. " identifier: erika-mustermann\n"
  27. "- !person\n"
  28. " birth_date: 1976-02-01\n"
  29. " father: &id002 !person\n"
  30. " identifier: thomas-mustermann\n"
  31. " identifier: max-mustermann\n"
  32. " mother: *id001\n"
  33. " name: Max Mustermann\n"
  34. "- *id002\n"
  35. )
  36. @patch("sys.argv", ["", "persons/max-mustermann.yml", "persons/erika-mustermann.yml"])
  37. def test__list_multiple(capsys):
  38. _list()
  39. out, err = capsys.readouterr()
  40. assert not err
  41. assert out == (
  42. "- &id001 !person\n"
  43. " birth_date: 1957-08-12\n"
  44. " identifier: erika-mustermann\n"
  45. " name: Erika Mustermann\n"
  46. "- !person\n"
  47. " birth_date: 1976-02-01\n"
  48. " father: &id002 !person\n"
  49. " identifier: thomas-mustermann\n"
  50. " identifier: max-mustermann\n"
  51. " mother: *id001\n"
  52. " name: Max Mustermann\n"
  53. "- *id002\n"
  54. )
  55. @patch("sys.argv", ["", "persons"])
  56. def test__list_recurse_dir(capsys):
  57. _list()
  58. out, err = capsys.readouterr()
  59. assert not err
  60. assert out == (
  61. "- !person\n"
  62. " father: &id001 !person\n"
  63. " identifier: alice-father\n"
  64. " mother: &id002 !person\n"
  65. " identifier: alice-grandmother\n"
  66. " name: Grandma Test\n"
  67. " identifier: alice\n"
  68. " mother: &id003 !person\n"
  69. " identifier: alice-mother\n"
  70. " name: Mum Test\n"
  71. " name: Alice Test\n"
  72. "- *id001\n"
  73. "- *id002\n"
  74. "- *id003\n"
  75. "- &id004 !person\n"
  76. " birth_date: 1957-08-12\n"
  77. " identifier: erika-mustermann\n"
  78. " name: Erika Mustermann\n"
  79. "- !person\n"
  80. " birth_date: 1976-02-01\n"
  81. " father: &id005 !person\n"
  82. " identifier: thomas-mustermann\n"
  83. " identifier: max-mustermann\n"
  84. " mother: *id004\n"
  85. " name: Max Mustermann\n"
  86. "- *id005\n"
  87. )