ó ‰P[c@sËddlZddlZddlZddlZddlZddlZddlZddlZejƒZ e ej dR&R@RARBRRCtmark_report_seen(RR,RN((s2/usr/share/apport/testsuite/test_python_crashes.pyt test_existingcs " c Csù|jƒ}tjjƒ}|jt|ƒddƒtjƒ}t|ddƒ}|j|ƒWdQXx$tjj ƒD]}t j |ƒqyWt j j t j j|ƒdƒ}t jt j j|ƒ|ƒ|jt j |ƒtj|gdtjƒ}|jƒdjƒ}|j|jddƒ|jd |k|ƒtjjƒ}|jt|ƒddƒtjƒ}t|ddƒ}|j|ƒWdQX|jd |d kƒ|j|d |ƒ|j|d |ƒ|j|jƒ|jƒƒdS( s6Python crash of a symlinked program resolves to targetis(crashed Python program produced a reportiR1Ns script-linkRs4crashing test python program exits with failure codesThis should happen.s bin/pythonR2R:(R0RRR>R&R@RERRFRRRtpathtjointdirnametsymlinktbasenameRR!R"R#R$R%R'R(tcrash_signature( RR,RNtpr1Rt script_linkR.R/tpr2((s2/usr/share/apport/testsuite/test_python_crashes.pyt test_symlink}s2  ! c Csz|jdƒtjjƒ}d}|jt|ƒddƒ|jtjt j|dƒj ƒddƒtj j ƒ}t |ddƒ}|j|ƒWdQXd d d d d dddddg }|jt|ƒjt|jƒƒƒdƒ|jd|d kƒ|j|d|d ƒd|kr\|j|dttt j|dƒjƒƒƒn|j|d jd ƒƒdS(swith zapped sys.argv.simport sys sys.argv = Noneis(crashed Python program produced a reportii sreport has correct permissionsR1NR2R4R5R6R7R8R9R:R;R<sreport has necessary fieldss bin/pythonR=(R0RRR>R?R&R@RARBRRCRDRERRFR(RGRHRIRJRKRLRM(RRNRORRP((s2/usr/share/apport/testsuite/test_python_crashes.pyt test_no_argv£s( "   $  &cCs¬|jƒtjjƒ}d}|jt|ƒddƒtjjƒ}t |ddƒ}|j |ƒWdQX|j d|dkdƒ|j d |dk|dƒdS( s/Python environmental variables appear in reportis(crashed Python program produced a reportiR1NRR6sreport contains PYTHONPATHs/my/bogus/path( R0RRR>R?R&R@RDRERRFR((RRNROR((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_python_envÂs cCs6tjjƒ}|jt|ƒddtjƒƒdS(s'Assert that there are no crash reports.is"no crash reports present (cwd: %s)N(RRR>R&R@Rtgetcwd(RRN((s2/usr/share/apport/testsuite/test_python_crashes.pyt_assert_no_reportsÖsc Csàtjƒ}z¿x¸d D]°}tj|ƒtjdgdtjdtjdtjƒ}|jdƒ\}}|jƒ}|jƒ}|jd ks˜t ‚|d ksªt ‚d |ks¼t ‚|j ƒqWWd tj|ƒXd S(s4interactive Python sessions never generate a report.s/tmps /usr/locals/usrtpythontstdintstdoutRsraise ValueErroriR t ValueErrorN(s/tmps /usr/locals/usr( RR`tchdirR!R"R#R$R%R'tAssertionErrorRa(Rtorig_cwdtdR.toutR/((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_interactiveÝs     c Cstjdtjjƒ\}}tjdƒ}|dk rFtjd=ntj j tj j ƒ}d}|dk r€|tjdR@( RR-R,t orig_hometifpathtorig_ignore_filetrR.R/RN((s2/usr/share/apport/testsuite/test_python_crashes.pyt test_ignoringðsB          cCs¸d}d}zwxp||kr|jddƒtjjƒ}|sGPn|jt|ƒddƒtjj|dƒ|d7}qWWdtjdƒX|j |dƒ|j ||ƒdS(slimit successive reportsiiR+s/var/tmp/pytestcrashis*crashed Python program produced one reportN( R0RRR>R&R@RRRRt assertGreatert assertLess(RtcounttlimitRN((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_no_flooding(scCss|jddƒ|jƒ}|j|djdƒ|dƒ|jd|dk|dƒ|j|ddƒdS(s.DBus.Error.ServiceUnknown with an invalid nameR*sRimport dbus obj = dbus.SessionBus().get_object('com.example.NotExisting', '/Foo') R4s)org.freedesktop.DBus.Error.ServiceUnknowntDbusErrorAnalysiss1no service file providing com.example.NotExistingN(R0t _load_reportR(RMR&(RRO((s2/usr/share/apport/testsuite/test_python_crashes.pyt!test_dbus_service_unknown_invalid<s   !cCstjddgƒ|jddƒ|jƒ}|jd|dk|dƒ|j|djdƒ|dƒ|jd |dk|dƒd S( sLDBus.Error.ServiceUnknown with a valid name on a different bus (not running)tkillallsgvfsd-metadataR*s_import dbus obj = dbus.SystemBus().get_object('org.gtk.vfs.Metadata', '/org/gtk/vfs/metadata') s)org.freedesktop.DBus.Error.ServiceUnknownR4R~s<provided by /usr/share/dbus-1/services/gvfs-metadata.servicesgvfsd-metadata is not runningN(R!tcallR0RR(RM(RRO((s2/usr/share/apport/testsuite/test_python_crashes.pyt-test_dbus_service_unknown_wrongbus_notrunningHs   cCs}|jddƒ|jƒ}|jd|dk|dƒ|j|djdƒ|dƒ|jd|dk|dƒdS( sHDBus.Error.ServiceUnknown with a valid name on a different bus (running)R*söimport dbus # let the service be activated, to ensure it is running obj = dbus.SessionBus().get_object('org.gtk.vfs.Metadata', '/org/gtk/vfs/metadata') assert obj obj = dbus.SystemBus().get_object('org.gtk.vfs.Metadata', '/org/gtk/vfs/metadata') s)org.freedesktop.DBus.Error.ServiceUnknownR4R~s<provided by /usr/share/dbus-1/services/gvfs-metadata.servicesgvfsd-metadata is runningN(R0RR(RM(RRO((s2/usr/share/apport/testsuite/test_python_crashes.pyt*test_dbus_service_unknown_wrongbus_runningVs   cCs˜tjƒjddƒ}|j|dƒz*tjdddgƒ|jddƒWdtjdd dgƒXtj j ƒ}|j t |ƒd d ƒdS( s)DBus.Error.NoReply with a running servicesorg.gtk.vfs.Metadatas/org/gtk/vfs/metadataRs-STOPsgvfsd-metadataR*s²import dbus obj = dbus.SessionBus().get_object('org.gtk.vfs.Metadata', '/org/gtk/vfs/metadata') assert obj i = dbus.Interface(obj, 'org.freedesktop.DBus.Peer') i.Ping(timeout=1) Ns-CONTis>NoReply is an useless exception and should not create a report( tdbust SessionBust get_objecttassertNotEqualR?R!R‚R0RRR>R&R@(Rt metadata_objRN((s2/usr/share/apport/testsuite/test_python_crashes.pyt!test_dbus_service_timeout_runningfs  cCs{|jddƒ|jƒ}|j|djdƒ|dƒ|jd|dƒ|jd|ƒ|jd|jƒƒdS(s8Other DBusExceptions get an unwrapped original exceptionR*s•import dbus obj = dbus.SessionBus().get_object('org.gtk.vfs.Daemon', '/org/gtk/vfs/Daemon') dbus.Interface(obj, 'org.gtk.vfs.Daemon').Nonexisting(1) R4s(org.freedesktop.DBus.Error.UnknownMethodR~sHdbus.exceptions.DBusException(org.freedesktop.DBus.Error.UnknownMethod):N(R0RR(RMtassertInt assertNotInRY(RRO((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_dbus_service_other_error«s  ! cCsJ|jddƒ|jƒ}|d}|j|jƒd||fƒdS(s(OSError with errno and no known subclassR*s4def g(): raise OSError(99, 'something bad') g()R:s%s:OSError(99):%s@11:gN(R0RR&RY(RROtexe((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_generic_os_error»s    cCsJ|jddƒ|jƒ}|d}|j|jƒd||fƒdS(s+OSError without errno and no known subclassR*s0def g(): raise OSError('something bad') g()R:s%s:OSError:%s@11:gN(R0RR&RY(RRORŽ((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_generic_os_error_no_errnoÈs    cCsJ|jddƒ|jƒ}|d}|j|jƒd||fƒdS(sOSError with known subclassR*s?def g(): raise OSError(2, 'no such file /notexisting') g()R:s%s:FileNotFoundError:%s@11:gN(R0RR&RY(RRORŽ((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_subclassed_os_errorÕs    cCsatjjƒ}|jt|ƒddƒtjƒ}t|ddƒ}|j|ƒWdQX|S(s9Ensure that there is exactly one crash report and load itis(crashed Python program produced a reportiR1N(RRR>R&R@RERRF(RRNROR((s2/usr/share/apport/testsuite/test_python_crashes.pyRâs  N(t__name__t __module__R R?R0RQRSR]R^R_RaRkRxR}R€RƒR„RŠRRRR‘R(((s2/usr/share/apport/testsuite/test_python_crashes.pyRs( &  &     8    E  (tunittestRR!RRAtshutiltatexitR…tmkdtempttemp_report_dirRtregistertrmtreetapport.fileutilsRt apport.reporttTestCaseRtmain(((s2/usr/share/apport/testsuite/test_python_crashes.pyt sT     ÿÕ