person_collection.py 3.4 KB

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