Your IP : 172.28.240.42


Current Path : /usr/share/apport/testsuite/
Upload File :
Current File : //usr/share/apport/testsuite/test_python_crashes.pyc


Yc@sddlZddlZddlZddlZddlZddlZddlZddlZddlZej	Z
e
ejd<ejej
e
ddlZddlZdejfdYZejdS(iNtAPPORT_REPORT_DIRtTcBsheZdZdddZdZdZdZdZdZ	dZ
d	Zd
ZRS(cCs+x$tjjD]}tj|qWdS(N(tapportt	fileutilstget_all_reportstostunlink(tselftf((s2/usr/share/apport/testsuite/test_python_crashes.pyttearDownstcCs|r+|}tj|tjtjB}ntjdd\}}ztj|d|tj|tj|dt	j
|ddgdt	jdt	jd	tj}|j
d
}|j|jd
d|s|jd|k|n|jd
|k|Wdtj|X|S(sCreate a test crash.tdirs/var/tmps#!/usr/bin/python
import apport_python_hook
apport_python_hook.install()

def func(x):
    raise Exception(b'This should happen. \xe2\x99\xa5'.decode('UTF-8'))

%s
func(42)
ittestarg1ttestarg2tstdouttstderrtenvis4crashing test python program exits with failure codesThis should happen.tOSErrorN(RtopentO_CREATtO_WRONLYttempfiletmkstemptwritetclosetchmodt
subprocesstPopentPIPEtenvirontcommunicatetassertEqualt
returncodet
assertTruetassertFalseR(Rt	extracodet
scriptnametscripttfdtpterr((s2/usr/share/apport/testsuite/test_python_crashes.pyt_test_crashs&		
cCsZ|j}tjj}d}|jt|dd|jtjt	j|dj
ddtj}|j
t|ddddd	d
ddd
dddg}|jt|jt|jd|jd|dk|j|d||j|dd||j|djd|jd|dk|ddS(s+general operation of the Python crash hook.is(crashed Python program produced a reportiisreport has correct permissionstInterpreterPatht
PythonArgst	TracebacktProblemTypetProcEnviront
ProcStatustProcCmdlinetDatetExecutablePathtProcMapst
UserGroupssreport has necessary fieldss
bin/pythons['%s', 'testarg1', 'testarg2']s.func
    raise Exception(b'This should happen.N(R)RRtget_new_reportstNoneRtlentstattS_IMODERtst_modetproblem_reportt
ProblemReporttloadRR!tsettissubsettkeyst
startswith(RR%treportstprt
expected_keys((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_general@s("
	$	cCs|j}tjj}|jt|dd|jtjtj|dj	ddtjj
|dtjj}|jt|d|jd|}tjj}|jt|d|jd|}tjj}|jt|ddS(s1Python crash hook overwrites seen existing files.is(crashed Python program produced a reportiisreport has correct permissionsR$N(R)RRR5RR7R8R9RR:tmark_report_seen(RR%RB((s2/usr/share/apport/testsuite/test_python_crashes.pyt
test_existing]s"
c
Cs|jdtjj}d}|jt|dd|jtjt	j|dj
ddtj}|j
t|dddd	d
ddd
dddg
}|jt|jt|jd|jd|dk|j|djddS(swith zapped sys.argv.simport sys
sys.argv = Noneis(crashed Python program produced a reportiisreport has correct permissionsR*R,R-R.R/R0R1R2R3R4sreport has necessary fieldss
bin/pythonN(R)RRR5R6RR7R8R9RR:R;R<R=RR!R>R?R@RA(RRBRCRD((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_no_argvws 
"
	$cCs6tjj}|jt|ddtjdS(s'Assert that there are no crash reports.is"no crash reports present (cwd: %s)N(RRR5RR7Rtgetcwd(RRB((s2/usr/share/apport/testsuite/test_python_crashes.pyt_assert_no_reportssc	Cstj}zxd
D]}tj|tjdgdtjdtjdtj}|jd\}}|jd	kst|d
kstd|kst|j	qWWdtj|XdS(s4interactive Python sessions never generate a report.s/tmps
/usr/locals/usrtpythontstdinRRsraise ValueErroriR
t
ValueErrorN(s/tmps
/usr/locals/usr(
RRItchdirRRRRR tAssertionErrorRJ(Rtorig_cwdtdR'toutR(((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_interactives

c	Cstjdtjj\}}tjjtjj	}d
}ztj|dtj|tj
|dtjj|r|d}tj||ntjj}||d<|jd
}tj|ddgdtjd	tj}|jd
}|j|jd
d|jd|kWd
tj|tjj|rZtj|n|rstj||nXtjj}|jt|dd
S(s/the Python crash hook respects the ignore list.Rs#!/usr/bin/python
import apport_python_hook
apport_python_hook.install()

def func(x):
    raise Exception, 'This should happen.'

func(42)
is.apporttestR2RR
RRis4crashing test python program exits with failure codesException: This should happen.Ni(RRRRt
report_dirRtpatht
expandusertreportt_ignore_fileR6RRRtexiststrenametReporttmark_ignoreRRRRRR R!RR5R7(	RR&R%tifpathtorig_ignore_filetrR'R(RB((s2/usr/share/apport/testsuite/test_python_crashes.pyt
test_ignorings8	




cCsd}d}xp||kr~|jddtjj}|sDPn|jt|ddtjj|d|d7}qW|j|d|j||dS(slimit successive reportsiiR$s/var/tmp/pytestcrashis*crashed Python program produced one reportN(	R)RRR5RR7RFt
assertGreatert
assertLess(RtcounttlimitRB((s2/usr/share/apport/testsuite/test_python_crashes.pyttest_no_floodingscCstjjdd}|j|dz*tjdddg|jddWdtjdd	dgXtj	j
}|jt|d
ddS(s)DBus.Error.NoReply with a running servicesorg.gtk.vfs.Metadatas/org/gtk/vfs/metadatatkillalls-STOPsgvfsd-metadataR#simport 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_objecttassertNotEqualR6RtcallR)RRR5RR7(Rtmetadata_objRB((s2/usr/share/apport/testsuite/test_python_crashes.pyt!test_dbus_service_timeout_runnings	N(
t__name__t
__module__R	R6R)RERGRHRJRSR`ReRm(((s2/usr/share/apport/testsuite/test_python_crashes.pyRs	%						3	(tunittestRRRR8tsystshutiltatexitRgtmkdtempttemp_report_dirRtregistertrmtreetapport.fileutilsRR;tTestCaseRtmain(((s2/usr/share/apport/testsuite/test_python_crashes.pyt<module>
s`