
    Xi                         d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ d	 Zd
 Z G d de          ZdS )zTests which are meant to be run as root.

NOTE: keep this module compatible with unittest: we want to run this
file with the unittest runner, since pytest may not be installed for
the root user.
    N)FREEBSD)LINUX)OPENBSD)WINDOWS)
CI_TESTING)PsutilTestCasec                      t          t          d          r3t          t          d          rt          j        t          j                  S t          j                    S )Nclock_gettimeCLOCK_REALTIME)hasattrtimer
   r        n/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/psutil/tests/test_sudo.pyget_systimer      sF    t_%% 7'$8H*I*I 7!$"56669;;r   c                    t          t          d          rYt          t          d          rD	 t          j        t          j        |            d S # t          $ r t          j        d          w xY wt          rdd l}dd l	}t          j
                            | t          j        j                  }	 |                    |j        |j        |                                dz  |j        |j        |j        |j        t-          |j        dz                       d S # |j        $ r%}|j        dk    rt          j        d           d }~ww xY wt          j        d	          )
Nclock_settimer   z
needs rootr      i  i"  zneeds Administrator userzsetting systime not supported)r   r   r   r   PermissionErrorunittestSkipTestr   
pywintypeswin32apidatetimefromtimestamptimezoneutcSetSystemTimeyearmonth
isoweekdaydayhourminutesecondintmicroseconderrorwinerror)secsr   r   dterrs        r   set_systimer-   !   sr   t_%% A'$8H*I*I A	2t2D99999 	2 	2 	2#L111	2	 A,,T83D3HII	""!#		BNT)**	 	 	 	 	  	 	 	|t##'(BCCC	
  ?@@@s$   A A,.A$D 
E D>>Ec                   $   e Zd ZdZd Zd Zd Zd Z ej	        e
d          d             Z ej	        ed           ej	        ed	           ej	        ed
          d                                     Z ej	        e d          d             ZdS )TestUpdatedSystemTimez$Tests which update the system clock.c                 j    d| _         t                      | _        t          j                    | _        d S )NF)time_updatedr   	orig_timer   	monotonictime_startedselfs    r   setUpzTestUpdatedSystemTime.setUpB   s+    !$ N,,r   c                 |    | j         r4t          j                    | j        z
  }t	          | j        |z              d S d S N)r1   r   r3   r4   r-   r2   )r6   extra_ts     r   tearDownzTestUpdatedSystemTime.tearDownG   sG     	2n&&)::G011111	2 	2r   c                 B    t          | j        dz              d| _        d S )N  T)r-   r2   r1   r5   s    r   update_systimez$TestUpdatedSystemTime.update_systimeL   s%    DNT)*** r   c                     t          j                    }|                                  t          j                    }|                     ||           t	          ||z
            }|                     |dd           d S Nr=      )delta)psutil	boot_timer>   assertGreaterr&   assertAlmostEqualr6   t1t2diffs       r   test_boot_timez$TestUpdatedSystemTime.test_boot_timeQ   sv    2r"""27||tT33333r   zbroken on WINDOWSc                    t          j                                                    }|                                  t          j                                                    }t	          ||z
            }|                     |dd           d S r@   )rC   Processcreate_timer>   r&   rF   rG   s       r   test_proc_create_timez+TestUpdatedSystemTime.test_proc_create_timeZ   sx    
 ^))++^))++27||tT33333r   zskipped on CI for nowzbroken on OPENBSDzbroken on FREEBSDc                    t          j                    }|                                  t          j                    }|                     |                                |                                           |                     ||           d S r9   )rC   rM   r>   assertEqual
_get_ident)r6   p1p2s      r   test_proc_identz%TestUpdatedSystemTime.test_proc_idente   sr     ^^"--//:::R     r   z
LINUX onlyc                 2   t          j                    j                            d          }|                                  t          j        d           t          j                    j                            d          }|                     ||           d S )NT)r3   g?)rC   rM   _procrN   r>   r   sleeprQ   )r6   rH   rI   s      r   test_linux_monotonic_proc_timez4TestUpdatedSystemTime.test_linux_monotonic_proc_timeo   s    ^#//$/??
4^#//$/??R     r   N)__name__
__module____qualname____doc__r7   r;   r>   rK   r   skipIfr   rO   r   r   r   rU   r   rY   r   r   r   r/   r/   ?   s       ..- - -
2 2 2
! ! !
4 4 4 X_W1224 4 324 X_Z!899X_W122X_W122! ! 32 32 :9! X_Y--! ! .-! ! !r   r/   )r]   r   r   r   rC   r   r   r   r   psutil.testsr   r   r   r-   r/   r   r   r   <module>r`      s                                 # # # # # # ' ' ' ' ' '  A A A<6! 6! 6! 6! 6!N 6! 6! 6! 6! 6!r   