Coverage for tests\test_utils_jinja_filters.py: 100.00%

22 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-22 23:23 +0100

1# -*- coding: utf-8 -*- 

2 

3""" 

4* Name: interactive-clustering-gui/tests/test_utils_jinja_filters.py 

5* Description: Unittests for `app` jinja filters `timestamp_to_date`, `timestamp_to_hour`, `get_previous_key`, `get_next_key`. 

6* Author: Erwan Schild 

7* Created: 22/02/2022 

8* Licence: CeCILL (https://cecill.info/licences.fr.html) 

9""" 

10 

11# ============================================================================== 

12# IMPORT PYTHON DEPENDENCIES 

13# ============================================================================== 

14 

15from cognitivefactory.interactive_clustering_gui.app import ( 

16 get_next_key, 

17 get_previous_key, 

18 timestamp_to_date, 

19 timestamp_to_hour, 

20) 

21 

22# ============================================================================== 

23# test_timestamp_to_date 

24# ============================================================================== 

25 

26 

27async def test_timestamp_to_date(): 

28 """ 

29 Test the `timestamp_to_hour()` method. 

30 """ 

31 assert timestamp_to_date(timestamp=1658909898.219331) == "27/07/2022" 

32 

33 

34# ============================================================================== 

35# test_timestamp_to_hour 

36# ============================================================================== 

37 

38 

39async def test_timestamp_to_hour(): 

40 """ 

41 Test the `timestamp_to_hour()` method. 

42 """ 

43 assert timestamp_to_hour(timestamp=1658909898.219331) == "10:18:18" 

44 

45 

46# ============================================================================== 

47# test_get_previous_key 

48# ============================================================================== 

49 

50 

51async def test_get_previous_key(): 

52 """ 

53 Test the `get_previous_key()` method. 

54 """ 

55 dictionary = {"a": 0, "e": -2, "c": None, "b": 0, "d": [0, 2, 5]} 

56 assert get_previous_key(key="a", dictionary=dictionary) is None 

57 assert get_previous_key(key="e", dictionary=dictionary) == "a" 

58 assert get_previous_key(key="c", dictionary=dictionary) == "e" 

59 assert get_previous_key(key="b", dictionary=dictionary) == "c" 

60 assert get_previous_key(key="d", dictionary=dictionary) == "b" 

61 assert get_previous_key(key="UNKNOWN", dictionary=dictionary) is None 

62 

63 

64# ============================================================================== 

65# test_get_next_key 

66# ============================================================================== 

67 

68 

69async def test_get_next_key(): 

70 """ 

71 Test the `get_next_key()` method. 

72 """ 

73 dictionary = {"a": 0, "e": -2, "c": None, "b": 0, "d": [0, 2, 5]} 

74 assert get_next_key(key="a", dictionary=dictionary) == "e" 

75 assert get_next_key(key="e", dictionary=dictionary) == "c" 

76 assert get_next_key(key="c", dictionary=dictionary) == "b" 

77 assert get_next_key(key="b", dictionary=dictionary) == "d" 

78 assert get_next_key(key="d", dictionary=dictionary) is None 

79 assert get_next_key(key="UNKNOWN", dictionary=dictionary) is None