| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import re |
| 6 |
| 7 from google.appengine.api import users |
| 8 |
| 9 from common.findit_testcase import FinditTestCase |
| 10 from model.crash.crash_config import CrashConfig |
| 11 |
| 12 |
| 13 DUMMY_COMPILED_COMPONENT_PATTERNS = { |
| 14 "path_function_component": [ |
| 15 [ |
| 16 re.compile("src/comp1.*"), |
| 17 None, |
| 18 "Comp1>Dummy" |
| 19 ], |
| 20 [ |
| 21 re.compile("src/comp2.*"), |
| 22 re.compile("func2.*"), |
| 23 "Comp2>Dummy" |
| 24 ], |
| 25 ], |
| 26 "top_n": 4 |
| 27 } |
| 28 |
| 29 |
| 30 DUMMY_COMPONENT_PATTERNS = { |
| 31 "path_function_component": [ |
| 32 [ |
| 33 "src/comp1.*", |
| 34 "", |
| 35 "Comp1>Dummy" |
| 36 ], |
| 37 [ |
| 38 "src/comp2.*", |
| 39 "func2.*", |
| 40 "Comp2>Dummy" |
| 41 ], |
| 42 ], |
| 43 "top_n": 4 |
| 44 } |
| 45 |
| 46 CONFIG_DATA = { |
| 47 'component_classifier': DUMMY_COMPONENT_PATTERNS, |
| 48 } |
| 49 |
| 50 |
| 51 class CrashAnalysisTest(FinditTestCase): |
| 52 |
| 53 def setUp(self): |
| 54 super(CrashAnalysisTest, self).setUp() |
| 55 CrashConfig.Get().Update( |
| 56 users.User(email='admin@chromium.org'), True, **CONFIG_DATA) |
| 57 |
| 58 def _VerifyTwoCompiledComponentClassifierEqual(self, setting1, setting2): |
| 59 self.assertEqual(setting1['top_n'], setting2['top_n']) |
| 60 self.assertEqual(len(setting1['path_function_component']), |
| 61 len(setting2['path_function_component'])) |
| 62 |
| 63 for i, (path1, function1, component1) in enumerate( |
| 64 setting1['path_function_component']): |
| 65 path2, function2, component2 = setting2['path_function_component'][i] |
| 66 self.assertEqual(path1.pattern, path2.pattern) |
| 67 if not function1: |
| 68 self.assertEqual(function1, function2) |
| 69 else: |
| 70 self.assertEqual(function1.pattern, function2.pattern) |
| 71 self.assertEqual(component1, component2) |
| 72 |
| 73 def testClearCache(self): |
| 74 crash_config = CrashConfig.Get() |
| 75 crash_config.ClearCache() |
| 76 |
| 77 self.assertIsNone(crash_config.cached_component_classifier) |
| 78 self._VerifyTwoCompiledComponentClassifierEqual( |
| 79 crash_config.compiled_component_classifier, |
| 80 DUMMY_COMPILED_COMPONENT_PATTERNS) |
| 81 |
| 82 def testGetCompiledComponentClassifierSettingFromCache(self): |
| 83 crash_config = CrashConfig.Get() |
| 84 crash_config.ClearCache() |
| 85 |
| 86 crash_config.cached_component_classifier = DUMMY_COMPILED_COMPONENT_PATTERNS |
| 87 self._VerifyTwoCompiledComponentClassifierEqual( |
| 88 crash_config.compiled_component_classifier, |
| 89 DUMMY_COMPILED_COMPONENT_PATTERNS) |
| 90 |
| 91 def testGetCompiledComponentClassifierSetting(self): |
| 92 crash_config = CrashConfig.Get() |
| 93 self.assertEqual(crash_config.component_classifier, |
| 94 DUMMY_COMPONENT_PATTERNS) |
| 95 self._VerifyTwoCompiledComponentClassifierEqual( |
| 96 crash_config.compiled_component_classifier, |
| 97 DUMMY_COMPILED_COMPONENT_PATTERNS) |
| 98 |
| OLD | NEW |