Coverage for test/analyser_test.py: 100%

62 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2025-07-14 14:06 +0000

1#!python 

2# Copyright 2022, Arcangelo Massari <arcangelo.massari@unibo.it> 

3# 

4# Permission to use, copy, modify, and/or distribute this software for any purpose 

5# with or without fee is hereby granted, provided that the above copyright notice 

6# and this permission notice appear in all copies. 

7# 

8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 

9# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 

10# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, 

11# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 

12# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 

13# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 

14# SOFTWARE. 

15 

16import os 

17import unittest 

18 

19from oc_meta.lib.file_manager import get_csv_data 

20from oc_meta.plugins.analyser import OCMetaAnalyser, OCMetaCounter 

21 

22BASE = os.path.join('test', 'analyser') 

23OUTPUT = os.path.join(BASE, 'output') 

24 

25 

26class test_Analyser(unittest.TestCase): 

27 def test_merge_rows_by_id(self): 

28 ocmeta_counter = OCMetaAnalyser(csv_dump_path=BASE) 

29 ocmeta_counter.merge_rows_by_id(output_dir=OUTPUT) 

30 csv_0 = get_csv_data(os.path.join(OUTPUT, '303_2022-09-29T02-39-23.csv')) 

31 csv_1 = get_csv_data(os.path.join(OUTPUT, '304_2022-09-29T02-39-23.csv')) 

32 csv_2 = get_csv_data(os.path.join(OUTPUT, '304_2022-09-29T02-39-24.csv')) 

33 csv_2_old = get_csv_data(os.path.join(BASE, '304_2022-09-29T02-39-24.csv')) 

34 csv_expected_0 = [ 

35 {'id': 'omid:br/06015', 'title': 'Spatial Distribution of Ion Current Around HVDC Bundle Conductors', 'pub_date': '2012-01', 'page': '380-390', 'type': 'journal article', 'author': 'Zhou, Xiangxian [omid:ra/06016]; Cui, Xiang [omid:ra/06017]; Lu, Tiebing [omid:ra/06018]; Fang, Chao [omid:ra/06019]; Zhen, Yongzan [omid:ra/06020]', 'editor': '', 'publisher': 'Institute of Electrical and Electronics Engineers (IEEE) [crossref:263 omid:ra/0610]', 'volume': '27', 'venue': 'IEEE Transactions on Power Delivery [issn:0885-8977 issn:1937-4208 omid:br/06016]', 'issue': '1'}, 

36 {'id': 'omid:br/06038', 'title': 'Space-charge effects in high-density plasmas', 'pub_date': '1982-06', 'page': '454-461', 'type': 'journal article', 'author': 'Morrow, R [omid:ra/06037]', 'editor': '', 'publisher': 'Elsevier BV [crossref:78 omid:ra/0605]', 'volume': '46', 'venue': 'Journal of Computational Physics [issn:0021-9991 omid:br/0604]', 'issue': '3'}] 

37 csv_expected_1 = [ 

38 {'id': 'omid:br/06044', 'title': 'Spatial Distribution of Ion Current Around HVDC Bundle Conductors', 'pub_date': '2012-01', 'page': '380-390', 'type': 'journal article', 'author': 'Zhou, Xiangxian [omid:ra/06016]; Cui, Xiang [omid:ra/06017]; Lu, Tiebing [omid:ra/06018]; Fang, Chao [omid:ra/06019]; Zhen, Yongzan [omid:ra/06020]', 'editor': '', 'publisher': 'Institute of Electrical and Electronics Engineers (IEEE) [crossref:263 omid:ra/0610]', 'volume': '27', 'venue': 'IEEE Transactions on Power Delivery [issn:0885-8977 issn:1937-4208 omid:br/06016]', 'issue': '1'}, 

39 {'id': 'omid:br/06045', 'title': 'Space-charge effects in high-density plasmas', 'pub_date': '1982-06', 'page': '454-461', 'type': 'journal article', 'author': 'Morrow, R [omid:ra/06037]', 'editor': '', 'publisher': 'Elsevier BV [crossref:78 omid:ra/0605]', 'volume': '46', 'venue': 'Journal of Computational Physics [issn:0021-9991 omid:br/0604]', 'issue': '3'}] 

40 self.assertEqual(csv_0, csv_expected_0) 

41 self.assertEqual(csv_1, csv_expected_1) 

42 self.assertEqual(csv_2, csv_2_old) 

43 

44 def test_count_authors(self): 

45 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

46 count = ocmeta_counter.count(what='authors') 

47 self.assertEqual(count, '40') 

48 

49 def test_count_editor(self): 

50 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

51 count = ocmeta_counter.count(what='editors') 

52 self.assertEqual(count, '0') 

53 

54 def test_count_publisher(self): 

55 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

56 count = ocmeta_counter.count(what='publishers') 

57 self.assertEqual(count, '4') 

58 

59 def test_count_venues(self): 

60 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

61 count = ocmeta_counter.count(what='venues') 

62 self.assertEqual(count, '8') 

63 

64 def test_get_top_publishers_by_venue(self): 

65 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

66 top: list = ocmeta_counter.get_top(what='publishers', by_what='venue') 

67 expected_top = [ 

68 ('omid:ra/0610', {'name': 'Institute of Electrical and Electronics Engineers (IEEE)', 'total': 3}), 

69 ('omid:ra/0602', {'name': 'Springer Science and Business Media LLC', 'total': 3}), 

70 ('omid:ra/0605', {'name': 'Elsevier BV', 'total': 1}), 

71 ('omid:ra/06026', {'name': 'IOP Publishing', 'total': 1})] 

72 top.sort(key=lambda x: str(x[1]['total']) + x[0], reverse=True) 

73 self.assertEqual(top.sort(key=lambda x: str(x[1]['total']) + x[0], reverse=True), expected_top.sort(key=lambda x: str(x[1]['total']) + x[0], reverse=True)) 

74 

75 def test_get_top_publishers_by_publication(self): 

76 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

77 top = ocmeta_counter.get_top(what='publishers', by_what='publication') 

78 expected_top = [ 

79 ('institute of electrical and electronics engineers (ieee)', {'name': 'Institute of Electrical and Electronics Engineers (IEEE)', 'total': 6}), 

80 ('elsevier bv', {'name': 'Elsevier BV', 'total': 5}), 

81 ('springer science and business media llc', {'name': 'Springer Science and Business Media LLC', 'total': 4}), 

82 ('iop publishing', {'name': 'IOP Publishing', 'total': 2})] 

83 self.assertEqual(top, expected_top) 

84 

85 def test_get_top_venues_by_publication(self): 

86 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

87 top = ocmeta_counter.get_top(what='venues', by_what='publication') 

88 expected_top = [ 

89 ('omid:br/0604', {'name': 'Journal of Computational Physics', 'total': 5}), 

90 ('omid:br/06016', {'name': 'IEEE Transactions on Power Delivery', 'total': 3}), 

91 ('omid:br/06012', {'name': 'IEEE Transactions on Plasma Science', 'total': 2}), 

92 ('omid:br/06022', {'name': 'Journal of Physics D: Applied Physics', 'total': 2}), 

93 ('omid:br/0602', {'name': 'Insulation of High-Voltage Equipment', 'total': 1}), 

94 ('omid:br/0608', {'name': 'IEEE Transactions on Magnetics', 'total': 1}), 

95 ('omid:br/06020', {'name': 'Physics and Applications of Pseudosparks', 'total': 1}), 

96 ('omid:br/06043', {'name': 'Journal of Electrical Engineering & Technology', 'total': 1})] 

97 self.assertEqual(top.sort(key=lambda x: str(x[1]['total']) + x[0], reverse=True), expected_top.sort(key=lambda x: str(x[1]['total']) + x[0], reverse=True)) 

98 

99 def test_get_top_years_by_publication(self): 

100 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

101 top = ocmeta_counter.get_top(what='years', by_what='publication') 

102 expected_top = [ 

103 ('2012', {'total': 3}), 

104 ('1982', {'total': 3}), 

105 ('2000', {'total': 2}), 

106 ('1973', {'total': 1}), 

107 ('2003', {'total': 1}), 

108 ('1990', {'total': 1}), 

109 ('1980', {'total': 1}), 

110 ('1991', {'total': 1}), 

111 ('1979', {'total': 1}), 

112 ('2006', {'total': 1})] 

113 self.assertEqual(top.sort(key=lambda x: str(x[1]['total']) + x[0], reverse=True), expected_top.sort(key=lambda x: str(x[1]['total']) + x[0], reverse=True)) 

114 

115 def test_get_top_types_by_publication(self): 

116 ocmeta_counter = OCMetaCounter(csv_dump_path=OUTPUT) 

117 top = ocmeta_counter.get_top(what='types', by_what='publication') 

118 expected_top = [ 

119 ('journal article', {'total': 14}), 

120 ('book chapter', {'total': 2}), 

121 ('book', {'total': 1})] 

122 expected_top = [ 

123 ('journal article', {'total': 14}), 

124 ('journal', {'total': 6}), 

125 ('book', {'total': 3}), 

126 ('book chapter', {'total': 2})] 

127 self.assertEqual(top, expected_top)