Debian Codegraph @

testing/mozbase/mozcrash/tests/test_java_exception.py

raw
1 #!/usr/bin/env python
2 # coding=UTF-8
3
4 import mozunit
5 import pytest
6
7
8 @pytest.fixture
9 def test_log():
10 return [
11 "01-30 20:15:41.937 E/GeckoAppShell( 1703): >>> "
12 'REPORTING UNCAUGHT EXCEPTION FROM THREAD 9 ("GeckoBackgroundThread")',
13 "01-30 20:15:41.937 E/GeckoAppShell( 1703): java.lang.NullPointerException",
14 "01-30 20:15:41.937 E/GeckoAppShell( 1703):"
15 " at org.mozilla.gecko.GeckoApp$21.run(GeckoApp.java:1833)",
16 "01-30 20:15:41.937 E/GeckoAppShell( 1703):"
17 " at android.os.Handler.handleCallback(Handler.java:587)",
18 ]
19
20
21 def test_uncaught_exception(check_for_java_exception, test_log):
22 """Test for an exception which should be caught."""
23 assert 1 == check_for_java_exception(test_log)
24
25
26 def test_truncated_exception(check_for_java_exception, test_log):
27 """Test for an exception which should be caught which was truncated."""
28 truncated_log = list(test_log)
29 truncated_log[0], truncated_log[1] = truncated_log[1], truncated_log[0]
30
31 assert 1 == check_for_java_exception(truncated_log)
32
33
34 def test_unchecked_exception(check_for_java_exception, test_log):
35 """Test for an exception which should not be caught."""
36 passable_log = list(test_log)
37 passable_log[0] = (
38 "01-30 20:15:41.937 E/GeckoAppShell( 1703):"
39 ' >>> NOT-SO-BAD EXCEPTION FROM THREAD 9 ("GeckoBackgroundThread")'
40 )
41
42 assert 0 == check_for_java_exception(passable_log)
43
44
45 def test_test_name_unicode(check_for_java_exception, test_log):
46 """Test that check_for_crashes can handle unicode in dump_directory."""
47 assert 1 == check_for_java_exception(test_log, test_name="🍪", quiet=False)
48
49
50 if __name__ == "__main__":
51 mozunit.main()