_list_test.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # yamify - define family trees in YAML
  2. #
  3. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. from unittest.mock import patch
  18. import pytest
  19. from yamily._cli import _list
  20. @patch("sys.argv", ["", "non/existing/file.yml"])
  21. def test__read_non_existing():
  22. with pytest.raises(FileNotFoundError):
  23. _list()
  24. @patch("sys.argv", ["", "persons/erika-mustermann.yml"])
  25. def test__list_single_simple(capsys):
  26. _list()
  27. out, err = capsys.readouterr()
  28. assert not err
  29. assert out == (
  30. "- !person\n"
  31. " birth_date: 1957-08-12\n"
  32. " identifier: erika-mustermann\n"
  33. " name: Erika Mustermann\n"
  34. )
  35. @patch("sys.argv", ["", "persons/max-mustermann.yml"])
  36. def test__list_single_parents(capsys):
  37. _list()
  38. out, err = capsys.readouterr()
  39. assert not err
  40. assert out == (
  41. "- &id001 !person\n"
  42. " identifier: erika-mustermann\n"
  43. "- !person\n"
  44. " birth_date: 1976-02-01\n"
  45. " father: &id002 !person\n"
  46. " identifier: thomas-mustermann\n"
  47. " identifier: max-mustermann\n"
  48. " mother: *id001\n"
  49. " name: Max Mustermann\n"
  50. "- *id002\n"
  51. )
  52. @patch("sys.argv", ["", "persons/max-mustermann.yml", "persons/erika-mustermann.yml"])
  53. def test__list_multiple(capsys):
  54. _list()
  55. out, err = capsys.readouterr()
  56. assert not err
  57. assert out == (
  58. "- &id001 !person\n"
  59. " birth_date: 1957-08-12\n"
  60. " identifier: erika-mustermann\n"
  61. " name: Erika Mustermann\n"
  62. "- !person\n"
  63. " birth_date: 1976-02-01\n"
  64. " father: &id002 !person\n"
  65. " identifier: thomas-mustermann\n"
  66. " identifier: max-mustermann\n"
  67. " mother: *id001\n"
  68. " name: Max Mustermann\n"
  69. "- *id002\n"
  70. )
  71. @patch("sys.argv", ["", "persons"])
  72. def test__list_recurse_dir(capsys):
  73. _list()
  74. out, err = capsys.readouterr()
  75. assert not err
  76. assert out == (
  77. "- !person\n"
  78. " father: &id001 !person\n"
  79. " identifier: alice-father\n"
  80. " mother: &id002 !person\n"
  81. " identifier: alice-grandmother\n"
  82. " name: Grandma Test\n"
  83. " identifier: alice\n"
  84. " mother: &id003 !person\n"
  85. " identifier: alice-mother\n"
  86. " name: Mum Test\n"
  87. " name: Alice Test\n"
  88. "- *id001\n"
  89. "- *id002\n"
  90. "- *id003\n"
  91. "- &id004 !person\n"
  92. " birth_date: 1957-08-12\n"
  93. " identifier: erika-mustermann\n"
  94. " name: Erika Mustermann\n"
  95. "- !person\n"
  96. " birth_date: 1976-02-01\n"
  97. " father: &id005 !person\n"
  98. " identifier: thomas-mustermann\n"
  99. " identifier: max-mustermann\n"
  100. " mother: *id004\n"
  101. " name: Max Mustermann\n"
  102. "- *id005\n"
  103. )