Home | History | Annotate | Download | only in util
      1 # Copyright 2014 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 unittest
      6 
      7 from telemetry.internal.util import classes
      8 
      9 
     10 class ClassWithoutInitDefOne: # pylint: disable=old-style-class, no-init
     11   pass
     12 
     13 
     14 class ClassWithoutInitDefTwo(object):
     15   pass
     16 
     17 
     18 class ClassWhoseInitOnlyHasSelf(object):
     19   def __init__(self):
     20     pass
     21 
     22 
     23 class ClassWhoseInitWithDefaultArguments(object):
     24   def __init__(self, dog=1, cat=None, cow=None, fud='a'):
     25     pass
     26 
     27 
     28 class ClassWhoseInitWithDefaultArgumentsAndNonDefaultArguments(object):
     29   def __init__(self, x, dog=1, cat=None, fish=None, fud='a'):
     30     pass
     31 
     32 
     33 class ClassesUnitTest(unittest.TestCase):
     34 
     35   def testIsDirectlyConstructableReturnsTrue(self):
     36     self.assertTrue(classes.IsDirectlyConstructable(ClassWithoutInitDefOne))
     37     self.assertTrue(classes.IsDirectlyConstructable(ClassWithoutInitDefTwo))
     38     self.assertTrue(classes.IsDirectlyConstructable(ClassWhoseInitOnlyHasSelf))
     39     self.assertTrue(
     40         classes.IsDirectlyConstructable(ClassWhoseInitWithDefaultArguments))
     41 
     42   def testIsDirectlyConstructableReturnsFalse(self):
     43     self.assertFalse(
     44         classes.IsDirectlyConstructable(
     45             ClassWhoseInitWithDefaultArgumentsAndNonDefaultArguments))
     46