person_collection_test.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. import datetime
  18. from yamily import Person, PersonCollection
  19. def test_add_person_again():
  20. collection = PersonCollection()
  21. alice1 = Person("alice")
  22. alice1.name = "Alice"
  23. collection.add_person(alice1)
  24. alice2 = Person("alice")
  25. alice2.birth_date = datetime.date(2019, 12, 23)
  26. alice2.death_date = datetime.date(1919, 12, 23)
  27. collection.add_person(alice2)
  28. assert len(list(collection)) == 1
  29. assert collection["alice"].name == "Alice"
  30. assert collection["alice"].birth_date == datetime.date(2019, 12, 23)
  31. assert collection["alice"].death_date == datetime.date(1919, 12, 23)
  32. def test_add_person_unknown_parents():
  33. collection = PersonCollection()
  34. alice = Person("alice")
  35. alice.name = "Alice"
  36. alice.birth_date = datetime.date(2019, 12, 23)
  37. alice.mother = Person("mother")
  38. alice.father = Person("father")
  39. collection.add_person(alice)
  40. assert collection["alice"].birth_date == datetime.date(2019, 12, 23)
  41. assert collection["alice"] is alice
  42. assert collection["mother"] is alice.mother
  43. assert collection["father"] is alice.father
  44. def test_add_person_known_parents():
  45. collection = PersonCollection()
  46. mother = Person("mother")
  47. mother.name = "Mum"
  48. collection.add_person(mother)
  49. collection.add_person(Person("father"))
  50. alice = Person("alice")
  51. alice.name = "Alice"
  52. alice.birth_date = datetime.date(2019, 12, 23)
  53. alice.mother = Person("mother")
  54. alice.father = Person("father")
  55. collection.add_person(alice)
  56. assert collection["alice"].birth_date == datetime.date(2019, 12, 23)
  57. assert collection["alice"] is alice
  58. assert collection["mother"] is mother
  59. assert collection["mother"] is alice.mother
  60. assert collection["alice"].mother.name == "Mum"
  61. assert collection["father"] is alice.father
  62. def test_add_person_later_parents():
  63. collection = PersonCollection()
  64. alice = Person("alice")
  65. alice.name = "Alice"
  66. alice.birth_date = datetime.date(2019, 12, 23)
  67. alice.mother = Person("mother")
  68. alice.father = Person("father")
  69. collection.add_person(alice)
  70. assert collection["mother"].name is None
  71. assert collection["father"].name is None
  72. mother = Person("mother")
  73. mother.name = "Mum"
  74. stored_mother = collection.add_person(mother)
  75. father = Person("father")
  76. father.name = "Dad"
  77. stored_father = collection.add_person(father)
  78. assert collection["alice"].birth_date == datetime.date(2019, 12, 23)
  79. assert collection["alice"] is alice
  80. assert collection["mother"] is alice.mother
  81. assert collection["mother"] is stored_mother
  82. assert collection["alice"].mother.name == "Mum"
  83. assert collection["father"] is alice.father
  84. assert collection["father"] is stored_father
  85. assert collection["alice"].father.name == "Dad"