Coverage for test/test_functions.py: 100%

37 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-23 02:22 +0000

1import pytest 

2 

3from application.util.functions import * 

4from test.data.vars_responses import ex_23060001 

5from test.data.worms_responses import clownfish_tree 

6 

7 

8class TestFunctions: 

9 def test_parse_datetime_micro(self): 

10 date_time = parse_datetime('2014-09-05T14:08:41.492Z') 

11 assert date_time == datetime(2014, 9, 5, 14, 8, 41, 492000) 

12 

13 def test_parse_datetime_no_micro(self): 

14 date_time = parse_datetime('2014-09-05T14:08:41Z') 

15 assert date_time == datetime(2014, 9, 5, 14, 8, 41) 

16 

17 def test_parse_datetime_fail(self): 

18 with pytest.raises(Exception): 

19 parse_datetime('fail') 

20 

21 def test_extract_recorded_datetime_no_micro(self): 

22 date_time = extract_recorded_datetime(ex_23060001['annotations'][0]) 

23 assert date_time == datetime(2023, 8, 24, 18, 36, 14) 

24 

25 def test_extract_recorded_datetime_round_up(self): 

26 date_time = extract_recorded_datetime(ex_23060001['annotations'][1]) 

27 assert date_time == datetime(2023, 8, 24, 21, 28, 26) 

28 

29 def test_extract_recorded_datetime_round_down(self): 

30 date_time = extract_recorded_datetime(ex_23060001['annotations'][2]) 

31 assert date_time == datetime(2014, 9, 20, 14, 13, 23) 

32 

33 def test_extract_recorded_datetime_fail(self): 

34 assert extract_recorded_datetime({}) is None 

35 

36 def test_get_association(self): 

37 test_obj = get_association(ex_23060001['annotations'][1], 'upon') 

38 assert test_obj == { 

39 'uuid': 'c4eaa100-upon', 

40 'link_name': 'upon', 

41 'to_concept': 'sed', 

42 'link_value': 'nil', 

43 'mime_type': 'text/plain' 

44 } 

45 

46 def test_get_association_none(self): 

47 test_obj = get_association(ex_23060001['annotations'][0], 'test') 

48 assert test_obj == {} 

49 

50 def test_format_annotator_normal(self): 

51 assert format_annotator(ex_23060001['annotations'][0]['observer']) == 'Nikki Cunanan' 

52 

53 def test_format_annotator_harold(self): 

54 assert format_annotator('hcarlson') == 'Harold Carlson' 

55 

56 def test_flatten_taxa_tree(self): 

57 assert flatten_taxa_tree(clownfish_tree, {}) == { 

58 'superdomain': 'Biota', 

59 'kingdom': 'Animalia', 

60 'phylum': 'Chordata', 

61 'subphylum': 'Vertebrata', 

62 'infraphylum': 'Gnathostomata', 

63 'parvphylum': 'Osteichthyes', 

64 'gigaclass': 'Actinopterygii', 

65 'superclass': 'Actinopteri', 

66 'class': 'Teleostei', 

67 'order': 'Ovalentaria incertae sedis', 

68 'family': 'Pomacentridae', 

69 'subfamily': 'Amphiprioninae', 

70 }