How to use _base_class method in molecule

Best Python code snippet using molecule_python

discover_unittest.py

Source:discover_unittest.py Github

copy

Full Screen

1# Copyright 2013 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import os5import unittest6from py_utils import discover7class DiscoverTest(unittest.TestCase):8 def setUp(self):9 self._base_dir = os.path.join(os.path.dirname(__file__), 'test_data')10 self._start_dir = os.path.join(self._base_dir, 'discoverable_classes')11 self._base_class = Exception12 def testDiscoverClassesWithIndexByModuleName(self):13 classes = discover.DiscoverClasses(self._start_dir,14 self._base_dir,15 self._base_class,16 index_by_class_name=False)17 actual_classes = dict((name, cls.__name__)18 for name, cls in classes.iteritems())19 expected_classes = {20 'another_discover_dummyclass': 'DummyExceptionWithParameterImpl1',21 'discover_dummyclass': 'DummyException',22 'parameter_discover_dummyclass': 'DummyExceptionWithParameterImpl2'23 }24 self.assertEqual(actual_classes, expected_classes)25 def testDiscoverDirectlyConstructableClassesWithIndexByClassName(self):26 classes = discover.DiscoverClasses(self._start_dir,27 self._base_dir,28 self._base_class,29 directly_constructable=True)30 actual_classes = dict((name, cls.__name__)31 for name, cls in classes.iteritems())32 expected_classes = {33 'dummy_exception': 'DummyException',34 'dummy_exception_impl1': 'DummyExceptionImpl1',35 'dummy_exception_impl2': 'DummyExceptionImpl2',36 }37 self.assertEqual(actual_classes, expected_classes)38 def testDiscoverClassesWithIndexByClassName(self):39 classes = discover.DiscoverClasses(self._start_dir, self._base_dir,40 self._base_class)41 actual_classes = dict((name, cls.__name__)42 for name, cls in classes.iteritems())43 expected_classes = {44 'dummy_exception': 'DummyException',45 'dummy_exception_impl1': 'DummyExceptionImpl1',46 'dummy_exception_impl2': 'DummyExceptionImpl2',47 'dummy_exception_with_parameter_impl1':48 'DummyExceptionWithParameterImpl1',49 'dummy_exception_with_parameter_impl2':50 'DummyExceptionWithParameterImpl2'51 }52 self.assertEqual(actual_classes, expected_classes)53 def testDiscoverClassesWithPatternAndIndexByModule(self):54 classes = discover.DiscoverClasses(self._start_dir,55 self._base_dir,56 self._base_class,57 pattern='another*',58 index_by_class_name=False)59 actual_classes = dict((name, cls.__name__)60 for name, cls in classes.iteritems())61 expected_classes = {62 'another_discover_dummyclass': 'DummyExceptionWithParameterImpl1'63 }64 self.assertEqual(actual_classes, expected_classes)65 def testDiscoverDirectlyConstructableClassesWithPatternAndIndexByClassName(66 self):67 classes = discover.DiscoverClasses(self._start_dir,68 self._base_dir,69 self._base_class,70 pattern='another*',71 directly_constructable=True)72 actual_classes = dict((name, cls.__name__)73 for name, cls in classes.iteritems())74 expected_classes = {75 'dummy_exception_impl1': 'DummyExceptionImpl1',76 'dummy_exception_impl2': 'DummyExceptionImpl2',77 }78 self.assertEqual(actual_classes, expected_classes)79 def testDiscoverClassesWithPatternAndIndexByClassName(self):80 classes = discover.DiscoverClasses(self._start_dir,81 self._base_dir,82 self._base_class,83 pattern='another*')84 actual_classes = dict((name, cls.__name__)85 for name, cls in classes.iteritems())86 expected_classes = {87 'dummy_exception_impl1': 'DummyExceptionImpl1',88 'dummy_exception_impl2': 'DummyExceptionImpl2',89 'dummy_exception_with_parameter_impl1':90 'DummyExceptionWithParameterImpl1',91 }92 self.assertEqual(actual_classes, expected_classes)93class ClassWithoutInitDefOne: # pylint: disable=old-style-class, no-init94 pass95class ClassWithoutInitDefTwo(object):96 pass97class ClassWhoseInitOnlyHasSelf(object):98 def __init__(self):99 pass100class ClassWhoseInitWithDefaultArguments(object):101 def __init__(self, dog=1, cat=None, cow=None, fud='a'):102 pass103class ClassWhoseInitWithDefaultArgumentsAndNonDefaultArguments(object):104 def __init__(self, x, dog=1, cat=None, fish=None, fud='a'):105 pass106class IsDirectlyConstructableTest(unittest.TestCase):107 def testIsDirectlyConstructableReturnsTrue(self):108 self.assertTrue(discover.IsDirectlyConstructable(ClassWithoutInitDefOne))109 self.assertTrue(discover.IsDirectlyConstructable(ClassWithoutInitDefTwo))110 self.assertTrue(discover.IsDirectlyConstructable(ClassWhoseInitOnlyHasSelf))111 self.assertTrue(112 discover.IsDirectlyConstructable(ClassWhoseInitWithDefaultArguments))113 def testIsDirectlyConstructableReturnsFalse(self):114 self.assertFalse(115 discover.IsDirectlyConstructable(...

Full Screen

Full Screen

lists.py

Source:lists.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import abc3import six4from modularodm.query.querydialect import DefaultQueryDialect as Q5@six.add_metaclass(abc.ABCMeta)6class List(list):7 def __init__(self, value=None, literal=False, **kwargs):8 value = value or []9 self._base_class = kwargs.get('base_class', None)10 if literal:11 super(List, self).__init__(value)12 else:13 super(List, self).__init__()14 self.extend(value)15class BaseForeignList(List):16 @abc.abstractmethod17 def _to_primary_keys(self):18 pass19 @abc.abstractmethod20 def _from_value(self, value):21 pass22 def _to_data(self):23 return list(super(BaseForeignList, self).__iter__())24 def __iter__(self):25 if self:26 return (self[idx] for idx in range(len(self)))27 return iter([])28 def __setitem__(self, key, value):29 super(BaseForeignList, self).__setitem__(key, self._from_value(value))30 def insert(self, index, value):31 super(BaseForeignList, self).insert(index, self._from_value(value))32 def append(self, value):33 super(BaseForeignList, self).append(self._from_value(value))34 def extend(self, iterable):35 for item in iterable:36 self.append(item)37 def remove(self, value):38 super(BaseForeignList, self).remove(self._from_value(value))39class ForeignList(BaseForeignList):40 def _from_value(self, value):41 return self._base_class._to_primary_key(value)42 def _to_primary_keys(self):43 return self._to_data()44 def __reversed__(self):45 return ForeignList(46 super(ForeignList, self).__reversed__(),47 base_class=self._base_class48 )49 def __getitem__(self, item):50 result = super(ForeignList, self).__getitem__(item)51 if isinstance(item, slice):52 return ForeignList(result, base_class=self._base_class)53 return self._base_class.load(result)54 def __getslice__(self, i, j):55 result = super(ForeignList, self).__getslice__(i, j)56 return ForeignList(result, base_class=self._base_class)57 def __contains__(self, item):58 keys = self._to_primary_keys()59 if isinstance(item, self._base_class):60 return item._primary_key in keys61 if isinstance(item, self._base_class._primary_type):62 return item in keys63 return False64 def index(self, value, start=None, stop=None):65 start = 0 if start is None else start66 stop = len(self) if stop is None else stop67 keys = self._to_primary_keys()68 if isinstance(value, self._base_class):69 return keys.index(value._primary_key, start, stop)70 if isinstance(value, self._base_class._primary_type):71 return keys.index(value, start, stop)72 raise ValueError('{0} is not in list'.format(value))73 def find(self, query=None):74 combined_query = Q(75 self._base_class._primary_name,76 'in',77 self._to_primary_keys()78 )79 if query is not None:80 combined_query = combined_query & query81 return self._base_class.find(combined_query)82class AbstractForeignList(BaseForeignList):83 def _from_value(self, value):84 if hasattr(value, '_primary_key'):85 return (86 value._primary_key,87 value._name88 )89 return value90 def _to_primary_keys(self):91 return [92 item[0]93 for item in self._to_data()94 ]95 def __reversed__(self):96 return AbstractForeignList(97 super(AbstractForeignList, self).__reversed__()98 )99 def get_foreign_object(self, value):100 from modularodm import StoredObject101 return StoredObject.get_collection(value[1])\102 .load(value[0])103 def __getitem__(self, item):104 result = super(AbstractForeignList, self).__getitem__(item)105 if isinstance(item, slice):106 return AbstractForeignList(result)107 return self.get_foreign_object(result)108 def __getslice__(self, i, j):109 result = super(AbstractForeignList, self).__getslice__(i, j)110 return AbstractForeignList(result)111 def __contains__(self, item):112 keys = self._to_primary_keys()113 if hasattr(item, '_primary_key'):114 return item._primary_key in keys115 elif isinstance(item, tuple):116 return item[0] in keys117 return item in keys118 def index(self, value, start=None, stop=None):119 start = 0 if start is None else start120 stop = len(self) if stop is None else stop121 keys = self._to_primary_keys()122 if hasattr(value, '_primary_key'):123 return keys.index(value._primary_key, start, stop)124 elif isinstance(value, tuple):125 return keys.index(value[0], start, stop)126 else:127 try:128 return keys.index(value, start, stop)129 except ValueError:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful