File indexing completed on 2026-04-10 08:39:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 import unittest
0011 import os
0012
0013 from pilot.api import analytics
0014
0015
0016 class TestAnalytics(unittest.TestCase):
0017 """
0018 Unit tests for the Analytics package.
0019 """
0020
0021 def setUp(self):
0022
0023 self.client = analytics.Analytics()
0024
0025 def test_linear_fit(self):
0026 """
0027 Make sure that a linear fit works.
0028
0029 :return: (assertion).
0030 """
0031
0032 self.assertIsInstance(self.client, analytics.Analytics)
0033
0034 x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
0035 y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
0036
0037 fit = self.client.fit(x, y)
0038 slope = fit.slope()
0039 intersect = fit.intersect()
0040
0041 self.assertEqual(type(slope), float)
0042 self.assertEqual(slope, 1.0)
0043 self.assertEqual(type(intersect), float)
0044 self.assertEqual(intersect, 0.0)
0045
0046 y = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
0047
0048 fit = self.client.fit(x, y)
0049 slope = fit.slope()
0050
0051 self.assertEqual(slope, -1.0)
0052
0053 def test_parsing_memory_monitor_data(self):
0054 """
0055 Read and fit PSS vs Time from memory monitor output file.
0056
0057 :return: (assertion).
0058 """
0059
0060
0061 filename = 'pilot/test/resource/memory_monitor_output.txt'
0062 self.assertEqual(os.path.exists(filename), True)
0063
0064 table = self.client.get_table(filename)
0065
0066 self.assertEqual(type(table), dict)
0067
0068 x = table['Time']
0069 y = table['PSS']
0070 fit = self.client.fit(x, y)
0071
0072 slope = fit.slope()
0073
0074 self.assertEqual(type(slope), float)
0075 self.assertGreater(slope, 0)
0076
0077
0078 if __name__ == '__main__':
0079 unittest.main()