1
0

test_utils.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import pytest
  2. from myanimebot.utils import MediaType, Service, filter_name, replace_all
  3. from myanimebot.globals import SERVICE_MAL, SERVICE_ANILIST
  4. def test_MediaType_from_str():
  5. # Testing for ANIME
  6. assert MediaType.ANIME == MediaType.from_str('ANIME')
  7. assert MediaType.ANIME == MediaType.from_str('anime')
  8. assert MediaType.ANIME == MediaType.from_str('ANiMe')
  9. assert MediaType.ANIME == MediaType.from_str('anime_list')
  10. assert MediaType.ANIME == MediaType.from_str('ANIME_LIST')
  11. assert MediaType.ANIME == MediaType.from_str('ANiMe_LiST')
  12. # Testing for MANGA
  13. assert MediaType.MANGA == MediaType.from_str('MANGA')
  14. assert MediaType.MANGA == MediaType.from_str('manga')
  15. assert MediaType.MANGA == MediaType.from_str('ManGA')
  16. assert MediaType.MANGA == MediaType.from_str('manga_list')
  17. assert MediaType.MANGA == MediaType.from_str('MANGA_LIST')
  18. assert MediaType.MANGA == MediaType.from_str('ManGA_LiSt')
  19. # Testing incorrect MediaType
  20. with pytest.raises(NotImplementedError, match='Cannot convert "TEST_LIST" to a MediaType'):
  21. MediaType.from_str('TEST_LIST')
  22. with pytest.raises(NotImplementedError, match='Cannot convert "Blabla" to a MediaType'):
  23. MediaType.from_str('Blabla')
  24. with pytest.raises(NotImplementedError, match='Cannot convert "Toto" to a MediaType'):
  25. MediaType.from_str('Toto')
  26. with pytest.raises(NotImplementedError, match='Cannot convert "ANIMU" to a MediaType'):
  27. MediaType.from_str('ANIMU')
  28. with pytest.raises(NotImplementedError, match='Cannot convert "mango" to a MediaType'):
  29. MediaType.from_str('mango')
  30. def test_Service_from_str():
  31. # Testing for MAL
  32. assert Service.MAL == Service.from_str('MAL')
  33. assert Service.MAL == Service.from_str('MYANIMELIST')
  34. assert Service.MAL == Service.from_str(SERVICE_MAL)
  35. assert Service.MAL == Service.from_str('MaL')
  36. assert Service.MAL == Service.from_str('mal')
  37. assert Service.MAL == Service.from_str('myanimelist')
  38. assert Service.MAL == Service.from_str('mYANimEliST')
  39. # Testing for Anilist
  40. assert Service.ANILIST == Service.from_str('AniList')
  41. assert Service.ANILIST == Service.from_str('AL')
  42. assert Service.ANILIST == Service.from_str(SERVICE_ANILIST)
  43. assert Service.ANILIST == Service.from_str('ANILIST')
  44. assert Service.ANILIST == Service.from_str('anilist')
  45. assert Service.ANILIST == Service.from_str('al')
  46. assert Service.ANILIST == Service.from_str('Al')
  47. # Testing incorrect Services
  48. with pytest.raises(NotImplementedError, match='Cannot convert "Kitsu" to a Service'):
  49. Service.from_str('Kitsu')
  50. with pytest.raises(NotImplementedError, match='Cannot convert "toto" to a Service'):
  51. Service.from_str('toto')
  52. with pytest.raises(NotImplementedError, match='Cannot convert "ani list" to a Service'):
  53. Service.from_str('ani list')
  54. with pytest.raises(NotImplementedError, match='Cannot convert "mla" to a Service'):
  55. Service.from_str('mla')
  56. def test_replace_all():
  57. with pytest.raises(AttributeError):
  58. replace_all("texte", []) == "texte"
  59. assert replace_all("texte", {}) == "texte"
  60. assert replace_all("I is a string", {"is": "am"}) == "I am a string"
  61. def test_filter_name():
  62. assert filter_name("") != "toto"