Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:16

0001 #!/usr/bin/env python
0002 # Licensed under the Apache License, Version 2.0 (the "License");
0003 # you may not use this file except in compliance with the License.
0004 # You may obtain a copy of the License at
0005 # http://www.apache.org/licenses/LICENSE-2.0
0006 #
0007 # Authors:
0008 # - Paul Nilsson, paul.nilsson@cern.ch, 2018
0009 
0010 import unittest
0011 import os
0012 
0013 from pilot.util.workernode import collect_workernode_info, get_disk_space
0014 
0015 
0016 class TestUtils(unittest.TestCase):
0017     """
0018     Unit tests for utils functions.
0019     """
0020 
0021     def setUp(self):
0022         # skip tests if running on a Mac -- Macs don't have /proc
0023         self.mac = False
0024         if os.environ.get('MACOSX') == 'true' or not os.path.exists('/proc/meminfo'):
0025             self.mac = True
0026 
0027         from pilot.info import infosys
0028         infosys.init("CERN")
0029 
0030     def test_collect_workernode_info(self):
0031         """
0032         Make sure that collect_workernode_info() returns the proper types (float, float, float).
0033 
0034         :return: (assertion)
0035         """
0036 
0037         if self.mac:
0038             return True
0039 
0040         mem, cpu, disk = collect_workernode_info(path=os.getcwd())
0041 
0042         self.assertEqual(type(mem), float)
0043         self.assertEqual(type(cpu), float)
0044         self.assertEqual(type(disk), float)
0045 
0046         self.assertNotEqual(mem, 0.0)
0047         self.assertNotEqual(cpu, 0.0)
0048         self.assertNotEqual(disk, 0.0)
0049 
0050     def test_get_disk_space(self):
0051         """
0052         Verify that get_disk_space() returns the proper type (int).
0053 
0054         :return: (assertion)
0055         """
0056 
0057         if self.mac:
0058             return True
0059 
0060         #queuedata = {'maxwdir': 123456789}
0061         from pilot.info import infosys
0062 
0063         diskspace = get_disk_space(infosys.queuedata)  ## FIX ME LATER
0064 
0065         self.assertEqual(type(diskspace), int)
0066 
0067 
0068 if __name__ == '__main__':
0069     unittest.main()