"""Contains the unit tests for the inner utils module"""

import unittest
import os
import pwd
import re
from tempfile import NamedTemporaryFile

from classyfd import File, utils


# Globals
IS_UNIX_LIKE = bool(os.name == "posix")


# Tests
class TestUtils(unittest.TestCase):
    def test_if_os_is_posix_compliant(self):
        expected_result = bool(os.name == "posix")
        actual_result = utils.determine_if_os_is_posix_compliant()
        self.assertEqual(actual_result, expected_result)
        return
    
    def test_get_random_file_name(self):
        with NamedTemporaryFile() as tf:
            f = File(tf.name)
            directory = f.parent
        
        random_file_name = utils.get_random_file_name(directory)
        self.assertEqual(len(random_file_name), 32)
        
        random_file_path = os.path.join(directory, random_file_name)
        self.assertFalse(os.path.exists(random_file_path))
        
        return
    

@unittest.skipUnless(IS_UNIX_LIKE, "Test supported on Unix-like systems only")
class TestUtilsUnixLike(unittest.TestCase):
    def test_if_running_as_root_user(self):
        expected_result = bool(
            os.geteuid() == 0 or 
            pwd.getpwuid(os.geteuid()).pw_name.lower() == "root"
        )
        actual_result = utils.determine_if_running_as_root_user()
        self.assertEqual(actual_result, expected_result)
        return   
    
  


if __name__ == "__main__":
    unittest.main()
@@ -98,16 +98,33 @@
 port re%0A
+import functools%0A
 from tem

Add import of the functools module to tests/unit/test_utils.py