
    h                         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y)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        T/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/psutil/tests/test_sudo.pyget_systimer      s9    t_%'$8H*I!!$"5"56699;r   c                    t        t        d      r6t        t        d      r&	 t        j                  t        j                  |        y t        rdd l}dd l	}t        j                  j                  | t        j                  j                        }	 |j                  |j                  |j                   |j#                         dz  |j$                  |j&                  |j(                  |j*                  t-        |j.                  dz               y t        j                  d	      # t        $ r t        j                  d      w xY w# |j0                  $ r*}|j2                  dk(  rt        j                  d       d }~ww xY w)
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-   !   s*   t_%'$8H*I	2t22D9 
,,T83D3D3H3HI	""!#				BNNT)*	  ?@@/  	2##L11	2$  	||t#''(BCC	s$   $D A;E D>E:%E55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y)TestUpdatedSystemTimez$Tests which update the system clock.c                 b    d| _         t               | _        t        j                         | _        y )NF)time_updatedr   	orig_timer   	monotonictime_startedselfs    r   setUpzTestUpdatedSystemTime.setUpB   s"    !$ NN,r   c                     | j                   r:t        j                         | j                  z
  }t	        | j
                  |z          y y N)r1   r   r3   r4   r-   r2   )r6   extra_ts     r   tearDownzTestUpdatedSystemTime.tearDownG   s8    nn&):)::G01 r   c                 B    t        | j                  dz          d| _        y )N  T)r-   r2   r1   r5   s    r   update_systimez$TestUpdatedSystemTime.update_systimeL   s    DNNT)* r   c                     t        j                         }| j                          t        j                         }| j                  ||       t	        ||z
        }| j                  |dd       y Nr=      )delta)psutil	boot_timer>   assertGreaterr&   assertAlmostEqualr6   t1t2diffs       r   test_boot_timez$TestUpdatedSystemTime.test_boot_timeQ   s\    2r"27|tT3r   zbroken on WINDOWSc                     t        j                         j                         }| j                          t        j                         j                         }t	        ||z
        }| j                  |dd       y r@   )rC   Processcreate_timer>   r&   rF   rG   s       r   test_proc_create_timez+TestUpdatedSystemTime.test_proc_create_timeZ   s\    
 ^^))+^^))+27|tT3r   zskipped on CI for nowzbroken on OPENBSDzbroken on FREEBSDc                     t        j                         }| j                          t        j                         }| j                  |j	                         |j	                                | j                  ||       y r9   )rC   rM   r>   assertEqual
_get_ident)r6   p1p2s      r   test_proc_identz%TestUpdatedSystemTime.test_proc_idente   sT     ^^^^"--/:R r   z
LINUX onlyc                 *   t        j                         j                  j                  d      }| j	                          t        j                  d       t        j                         j                  j                  d      }| j                  ||       y )NT)r3   g?)rC   rM   _procrN   r>   r   sleeprQ   )r6   rH   rI   s      r   test_linux_monotonic_proc_timez4TestUpdatedSystemTime.test_linux_monotonic_proc_timeo   sj    ^^##//$/?

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
!
4 X__W124 34 X__Z!89X__W12X__W12! 3 3 :! X__Y-! .!r   r/   )r]   r   r   r   rC   r   r   r   r   psutil.testsr   r   r   r-   r/   r   r   r   <module>r`      sA            # 'A<6!N 6!r   