Home | History | Annotate | Download | only in core
      1 # Copyright (c) 2013 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 import os
      5 import unittest
      6 
      7 from telemetry.core import discover
      8 from telemetry.core import util
      9 
     10 class DiscoverTest(unittest.TestCase):
     11   def setUp(self):
     12     self._base_dir = util.GetUnittestDataDir()
     13     self._start_dir = os.path.join(self._base_dir, 'discoverable_classes')
     14     self._base_class = Exception
     15 
     16   def testDiscoverClassesBasic(self):
     17     classes = discover.DiscoverClasses(
     18         self._start_dir, self._base_dir, self._base_class)
     19 
     20     actual_classes = dict(
     21         (name, cls.__name__) for name, cls in classes.iteritems())
     22     expected_classes = {
     23         'discover_dummyclass': 'DummyException',
     24         'another_discover_dummyclass': 'DummyExceptionImpl2',
     25     }
     26     self.assertEqual(actual_classes, expected_classes)
     27 
     28   def testDiscoverClassesWithPattern(self):
     29     classes = discover.DiscoverClasses(
     30         self._start_dir, self._base_dir, self._base_class,
     31         pattern='another*')
     32 
     33     actual_classes = dict(
     34         (name, cls.__name__) for name, cls in classes.iteritems())
     35     expected_classes = {
     36         'another_discover_dummyclass': 'DummyExceptionImpl2',
     37     }
     38     self.assertEqual(actual_classes, expected_classes)
     39 
     40   def testDiscoverClassesByClassName(self):
     41     classes = discover.DiscoverClasses(
     42         self._start_dir, self._base_dir, self._base_class,
     43         index_by_class_name=True)
     44 
     45     actual_classes = dict(
     46         (name, cls.__name__) for name, cls in classes.iteritems())
     47     expected_classes = {
     48         'dummy_exception': 'DummyException',
     49         'dummy_exception_impl1': 'DummyExceptionImpl1',
     50         'dummy_exception_impl2': 'DummyExceptionImpl2',
     51     }
     52     self.assertEqual(actual_classes, expected_classes)
     53