Best Python code snippet using nose
test_factory.py
Source:test_factory.py
...19 abstractfactory_naive20)21class TestFactory(unittest.TestCase):22 def test_classes(self):23 self.assertEqual(inspect.isclass(simplefactory_naive.AbstractProduct), True)24 self.assertEqual(inspect.isclass(simplefactory_naive.ProductFactory), True)25 self.assertEqual(inspect.isclass(simplefactory_naive.Product1), True)26 self.assertEqual(inspect.isclass(simplefactory_naive.Product2), True)27 self.assertEqual(inspect.isclass(simplefactory_naive.Client), True)28 def test_instances(self):29 self.assertEqual(isinstance(simplefactory_naive.AbstractProduct, ABCMeta), True)30 self.assertEqual(isinstance(simplefactory_naive.Product1(), simplefactory_naive.AbstractProduct), True)31 self.assertEqual(isinstance(simplefactory_naive.Product2(), simplefactory_naive.AbstractProduct), True)32 33 def test_orderedproduct(self):34 factory = simplefactory_naive.ProductFactory()35 store = simplefactory_naive.Client(factory)36 product = store.order_product("product 1")37 self.assertEqual(product.get_product(), "I am Product A")38 product = store.order_product("product 2")39 self.assertEqual(product.get_product(), "I am Product B")40 product = store.order_product()41 self.assertEqual(product.get_product(), "I am Product B")42class TestFactoryPizza(unittest.TestCase):43 def test_classes(self):44 self.assertEqual(inspect.isclass(simplefactory_pizza.Pizza), True)45 self.assertEqual(inspect.isclass(simplefactory_pizza.DominoesPizzaFactory), True)46 self.assertEqual(inspect.isclass(simplefactory_pizza.MargheritaPizza), True)47 self.assertEqual(inspect.isclass(simplefactory_pizza.PeppyPaneerPizza), True)48 self.assertEqual(inspect.isclass(simplefactory_pizza.CheeseBurstPizza), True)49 self.assertEqual(inspect.isclass(simplefactory_pizza.FarmHousePizza), True)50 self.assertEqual(inspect.isclass(simplefactory_pizza.MexicanPizza), True)51 self.assertEqual(inspect.isclass(simplefactory_pizza.DominoesPizzaStore), True)52 def test_instances(self):53 self.assertEqual(isinstance(simplefactory_pizza.Pizza, ABCMeta), True)54 self.assertEqual(isinstance(simplefactory_pizza.MargheritaPizza(), simplefactory_pizza.Pizza), True)55 self.assertEqual(isinstance(simplefactory_pizza.PeppyPaneerPizza(), simplefactory_pizza.Pizza), True)56 self.assertEqual(isinstance(simplefactory_pizza.CheeseBurstPizza(), simplefactory_pizza.Pizza), True)57 self.assertEqual(isinstance(simplefactory_pizza.FarmHousePizza(), simplefactory_pizza.Pizza), True)58 self.assertEqual(isinstance(simplefactory_pizza.MexicanPizza(), simplefactory_pizza.Pizza), True)59 def test_orderedpizza(self):60 factory = simplefactory_pizza.DominoesPizzaFactory()61 store = simplefactory_pizza.DominoesPizzaStore(factory)62 pizza = store.order_pizza("cheeseburst")63 self.assertEqual(pizza.get_pizzaname(), "Cheese Burst")64 pizza = store.order_pizza("mexican")65 self.assertEqual(pizza.get_pizzaname(), "Mexican")66 pizza = store.order_pizza()67 self.assertEqual(pizza.get_pizzaname(), "Farm House")68class TestFactoryBurger(unittest.TestCase):69 def test_classes(self):70 self.assertEqual(inspect.isclass(simplefactory_burger.Burger), True)71 self.assertEqual(inspect.isclass(simplefactory_burger.BurgerFactory), True)72 self.assertEqual(inspect.isclass(simplefactory_burger.GrilledMushroomBurger), True)73 self.assertEqual(inspect.isclass(simplefactory_burger.MixVeggieBurger), True)74 self.assertEqual(inspect.isclass(simplefactory_burger.CaramalizedOnionBurger), True)75 self.assertEqual(inspect.isclass(simplefactory_burger.CheeseBurger), True)76 self.assertEqual(inspect.isclass(simplefactory_burger.BurgerStore), True)77 def test_instances(self):78 self.assertEqual(isinstance(simplefactory_burger.Burger, ABCMeta), True)79 self.assertEqual(isinstance(simplefactory_burger.MixVeggieBurger(), simplefactory_burger.Burger), True)80 self.assertEqual(isinstance(simplefactory_burger.GrilledMushroomBurger(), simplefactory_burger.Burger), True)81 self.assertEqual(isinstance(simplefactory_burger.CaramalizedOnionBurger(), simplefactory_burger.Burger), True)82 self.assertEqual(isinstance(simplefactory_burger.CheeseBurger(), simplefactory_burger.Burger), True)83 def test_orderedburger(self):84 factory = simplefactory_burger.BurgerFactory()85 store = simplefactory_burger.BurgerStore(factory)86 burger = store.order_burger("mixveggie")87 self.assertEqual(burger.get_burgername(), "Mix Veggie")88 burger = store.order_burger("grilledmushroom")89 self.assertEqual(burger.get_burgername(), "Grilled Mushroom")90 burger = store.order_burger()91 self.assertEqual(burger.get_burgername(), "Mix Veggie")92class TestFactoryMethodNaive(unittest.TestCase):93 def test_classes(self):94 self.assertEqual(inspect.isclass(factorymethod_naive.AbstractCreator), True)95 self.assertEqual(inspect.isclass(factorymethod_naive.ConcreteCreatorA), True)96 self.assertEqual(inspect.isclass(factorymethod_naive.ConcreteCreatorB), True)97 self.assertEqual(inspect.isclass(factorymethod_naive.AbstractProduct), True)98 self.assertEqual(inspect.isclass(factorymethod_naive.ConcreteProductA), True)99 self.assertEqual(inspect.isclass(factorymethod_naive.ConcreteProductB), True)100 def test_instances(self):101 self.assertEqual(isinstance(factorymethod_naive.AbstractCreator, ABCMeta), True)102 self.assertEqual(isinstance(factorymethod_naive.ConcreteCreatorA(), factorymethod_naive.AbstractCreator), True)103 self.assertEqual(isinstance(factorymethod_naive.ConcreteCreatorB(), factorymethod_naive.AbstractCreator), True)104 self.assertEqual(isinstance(factorymethod_naive.AbstractProduct, ABCMeta), True)105 self.assertEqual(isinstance(factorymethod_naive.ConcreteProductA(), factorymethod_naive.AbstractProduct), True)106 self.assertEqual(isinstance(factorymethod_naive.ConcreteProductB(), factorymethod_naive.AbstractProduct), True)107 def test_factorymethod(self):108 concretecreator = factorymethod_naive.ConcreteCreatorA()109 self.assertEqual(concretecreator.product.interface(), "I am in A")110class TestFactoryMethodCar(unittest.TestCase):111 def test_classes(self):112 self.assertEqual(inspect.isclass(factorymethod_car.Car), True)113 self.assertEqual(inspect.isclass(factorymethod_car.TeslaX), True)114 self.assertEqual(inspect.isclass(factorymethod_car.TeslaS), True)115 self.assertEqual(inspect.isclass(factorymethod_car.Tesla3), True)116 self.assertEqual(inspect.isclass(factorymethod_car.BMWi3s), True)117 self.assertEqual(inspect.isclass(factorymethod_car.BMW7), True)118 self.assertEqual(inspect.isclass(factorymethod_car.CarFactory), True)119 self.assertEqual(inspect.isclass(factorymethod_car.TeslaFactory), True)120 self.assertEqual(inspect.isclass(factorymethod_car.BMWFactory), True)121 def test_instances(self):122 self.assertEqual(isinstance(factorymethod_car.Car, ABCMeta), True)123 self.assertEqual(isinstance(factorymethod_car.TeslaX(), factorymethod_car.Car), True)124 self.assertEqual(isinstance(factorymethod_car.TeslaS(), factorymethod_car.Car), True)125 self.assertEqual(isinstance(factorymethod_car.Tesla3(), factorymethod_car.Car), True)126 self.assertEqual(isinstance(factorymethod_car.BMWi3s(), factorymethod_car.Car), True)127 self.assertEqual(isinstance(factorymethod_car.BMW7(), factorymethod_car.Car), True)128 self.assertEqual(isinstance(factorymethod_car.CarFactory, ABCMeta), True)129 self.assertEqual(isinstance(factorymethod_car.TeslaFactory(), factorymethod_car.CarFactory), True)130 self.assertEqual(isinstance(factorymethod_car.BMWFactory(), factorymethod_car.CarFactory), True)131 def test_orderedcar(self):132 teslafactory = factorymethod_car.TeslaFactory()133 bmwfactory = factorymethod_car.BMWFactory()134 car1 = teslafactory.order_car("tesla x")135 self.assertEqual(car1.get_carname(), "Tesla Model X")136 car2 = bmwfactory.order_car("bmw i3s")137 self.assertEqual(car2.get_carname(), "BMW i3s")138class TestFactoryMethodCellphone(unittest.TestCase):139 def test_classes(self):140 self.assertEqual(inspect.isclass(factorymethod_cellphone.Cellphone), True)141 self.assertEqual(inspect.isclass(factorymethod_cellphone.SamsungGalaxyJ8), True)142 self.assertEqual(inspect.isclass(factorymethod_cellphone.SamsungGalaxyA6), True)143 self.assertEqual(inspect.isclass(factorymethod_cellphone.OppoF7), True)144 self.assertEqual(inspect.isclass(factorymethod_cellphone.OppoF5), True)145 self.assertEqual(inspect.isclass(factorymethod_cellphone.CellphoneFactory), True)146 self.assertEqual(inspect.isclass(factorymethod_cellphone.SamsungFactory), True)147 self.assertEqual(inspect.isclass(factorymethod_cellphone.OppoFactory), True)148 def test_instances(self):149 self.assertEqual(isinstance(factorymethod_cellphone.Cellphone, ABCMeta), True)150 self.assertEqual(isinstance(factorymethod_cellphone.SamsungGalaxyJ8(), factorymethod_cellphone.Cellphone), True)151 self.assertEqual(isinstance(factorymethod_cellphone.SamsungGalaxyA6(), factorymethod_cellphone.Cellphone), True)152 self.assertEqual(isinstance(factorymethod_cellphone.OppoF7(), factorymethod_cellphone.Cellphone), True)153 self.assertEqual(isinstance(factorymethod_cellphone.OppoF5(), factorymethod_cellphone.Cellphone), True)154 self.assertEqual(isinstance(factorymethod_cellphone.CellphoneFactory, ABCMeta), True)155 self.assertEqual(isinstance(factorymethod_cellphone.SamsungFactory(), factorymethod_cellphone.CellphoneFactory), True)156 self.assertEqual(isinstance(factorymethod_cellphone.OppoFactory(), factorymethod_cellphone.CellphoneFactory), True)157 def test_orderedcellphone(self):158 samsungfactory = factorymethod_cellphone.SamsungFactory()159 c1 = samsungfactory.order_cellphone("J8")160 self.assertEqual(c1.get_cellphonename(), "Samsung Galaxy J8")161class TestAbstractFactoryShape(unittest.TestCase):162 def test_classes(self):163 self.assertEqual(inspect.isclass(abstractfactory_shape.DrawFactory), True)164 self.assertEqual(inspect.isclass(abstractfactory_shape.CircleFactory), True)165 self.assertEqual(inspect.isclass(abstractfactory_shape.TriangleFactory), True)166 self.assertEqual(inspect.isclass(abstractfactory_shape.CreateShape), True)167 self.assertEqual(inspect.isclass(abstractfactory_shape.FillShape), True)168 self.assertEqual(inspect.isclass(abstractfactory_shape.CircleShape), True)169 self.assertEqual(inspect.isclass(abstractfactory_shape.CircleColor), True)170 self.assertEqual(inspect.isclass(abstractfactory_shape.TriangleShape), True)171 self.assertEqual(inspect.isclass(abstractfactory_shape.TriangleColor), True)172 self.assertEqual(inspect.isclass(abstractfactory_shape.ShapeFactoryStore), True)173 def test_instances(self):174 self.assertEqual(isinstance(abstractfactory_shape.DrawFactory, ABCMeta), True)175 self.assertEqual(isinstance(abstractfactory_shape.CircleFactory(), abstractfactory_shape.DrawFactory), True)176 self.assertEqual(isinstance(abstractfactory_shape.TriangleFactory(), abstractfactory_shape.DrawFactory), True)177 self.assertEqual(isinstance(abstractfactory_shape.CreateShape, ABCMeta), True)178 self.assertEqual(isinstance(abstractfactory_shape.FillShape, ABCMeta), True)179 self.assertEqual(isinstance(abstractfactory_shape.CircleShape(), abstractfactory_shape.CreateShape), True)180 self.assertEqual(isinstance(abstractfactory_shape.CircleColor(), abstractfactory_shape.FillShape), True)181 self.assertEqual(isinstance(abstractfactory_shape.TriangleShape(), abstractfactory_shape.CreateShape), True)182 self.assertEqual(isinstance(abstractfactory_shape.TriangleColor(), abstractfactory_shape.FillShape), True)183class TestAbstractFactoryNaiveShape(unittest.TestCase):184 def test_classes(self):185 self.assertEqual(inspect.isclass(abstractfactory_naive.AbstractFactory), True)186 self.assertEqual(inspect.isclass(abstractfactory_naive.ConcreteFactory1), True)187 self.assertEqual(inspect.isclass(abstractfactory_naive.ConcreteFactory2), True)188 self.assertEqual(inspect.isclass(abstractfactory_naive.AbstractProductA), True)189 self.assertEqual(inspect.isclass(abstractfactory_naive.AbstractProductB), True)190 self.assertEqual(inspect.isclass(abstractfactory_naive.ConcreteProductA1), True)191 self.assertEqual(inspect.isclass(abstractfactory_naive.ConcreteProductA2), True)192 self.assertEqual(inspect.isclass(abstractfactory_naive.ConcreteProductB1), True)193 self.assertEqual(inspect.isclass(abstractfactory_naive.ConcreteProductB2), True)194 def test_instances(self):195 self.assertEqual(isinstance(abstractfactory_naive.AbstractFactory, ABCMeta), True)196 self.assertEqual(isinstance(abstractfactory_naive.ConcreteFactory1(), abstractfactory_naive.AbstractFactory), True)197 self.assertEqual(isinstance(abstractfactory_naive.ConcreteFactory2(), abstractfactory_naive.AbstractFactory), True)198 self.assertEqual(isinstance(abstractfactory_naive.AbstractProductA, ABCMeta), True)199 self.assertEqual(isinstance(abstractfactory_naive.AbstractProductB, ABCMeta), True)200 self.assertEqual(isinstance(abstractfactory_naive.ConcreteProductA1(), abstractfactory_naive.AbstractProductA), True)201 self.assertEqual(isinstance(abstractfactory_naive.ConcreteProductA2(), abstractfactory_naive.AbstractProductA), True)202 self.assertEqual(isinstance(abstractfactory_naive.ConcreteProductB1(), abstractfactory_naive.AbstractProductB), True)203 self.assertEqual(isinstance(abstractfactory_naive.ConcreteProductB2(), abstractfactory_naive.AbstractProductB), True)204 def test_factory(self):205 factory = abstractfactory_naive.ConcreteFactory1()206 p_a = factory.create_product_a()207 self.assertEqual(p_a.interface_a(), "I am in A1")
finding_test.py
Source:finding_test.py
...48 # Tests that the right error is silenced.49 def cvar_raises_nameerror(value):50 if value == cvar:51 raise NameError()52 return isclass(value)53 with mock.patch.object(inspect, 'isclass') as mock_isclass:54 mock_isclass.side_effect = cvar_raises_nameerror55 self.assertNotIn(cvar,56 finding.find_classes(modules=[this_module], classes=None))57 # Tests that the wrong error type is let through.58 def cvar_raises_valueerror(value):59 if value == cvar:60 raise ValueError()61 return isclass(value)62 with mock.patch.object(inspect, 'isclass') as mock_isclass:63 mock_isclass.side_effect = cvar_raises_valueerror64 with self.assertRaises(ValueError):65 finding.find_classes(modules=[this_module], classes=None)66 # Tests that an error relating to another attribute is let through.67 def foo_raises_nameerror(value):68 if value == foo:69 raise NameError()70 return isclass(value)71 with mock.patch.object(inspect, 'isclass') as mock_isclass:72 mock_isclass.side_effect = foo_raises_nameerror73 with self.assertRaises(NameError):74 finding.find_classes(modules=[this_module], classes=None)75 def test__find_classes_in_module_when_module_bases_is_not_tuple(self):76 # Test for the case when the __bases__ attributes of an imported77 # module is not a tuple that is expected.78 #79 # tensorboard 2.2.2 have such an example80 # from tensorboard.compat.tensorflow_stub import pywrap_tensorflow81 #82 # This mocks an imported module that has .__bases__ = 083 this_module = sys.modules[FindClassesTest.__module__]84 this_module.__bases__ = 0...
test_import_01.py
Source:test_import_01.py
...16 has_no_ROOT = True17##__________________________________________________________________||18@pytest.mark.skipif(has_no_pandas, reason="has no pandas")19def test_with_pandas():20 assert inspect.isclass(alphatwirl.collector.ToDataFrameWithDatasetColumn)21 assert inspect.isclass(alphatwirl.collector.WritePandasDataFrameToFile)22@pytest.mark.skipif(has_no_ROOT, reason="has no ROOT")23def test_with_ROOT():24 assert inspect.isclass(alphatwirl.roottree.BEvents)25 assert inspect.isclass(alphatwirl.roottree.BranchAddressManager)26 assert inspect.isclass(alphatwirl.roottree.BranchAddressManagerForVector)27def test_functions():28 assert inspect.isfunction(alphatwirl.mkdir_p)29 assert inspect.isfunction(alphatwirl.configure.build_counter_collector_pair)30def test_classes():31 assert inspect.isclass(alphatwirl.binning.Binning)32 assert inspect.isclass(alphatwirl.binning.Echo)33 assert inspect.isclass(alphatwirl.binning.Round)34 assert inspect.isclass(alphatwirl.binning.RoundLog)35 assert inspect.isclass(alphatwirl.binning.Combine)36 assert inspect.isclass(alphatwirl.collector.ToTupleListWithDatasetColumn)37 assert inspect.isclass(alphatwirl.collector.WriteListToFile)38 assert inspect.isclass(alphatwirl.concurrently.CommunicationChannel)39 assert inspect.isclass(alphatwirl.concurrently.CommunicationChannel0)40 assert inspect.isclass(alphatwirl.concurrently.TaskPackageDropbox)41 assert inspect.isclass(alphatwirl.concurrently.MultiprocessingDropbox)42 assert inspect.isclass(alphatwirl.concurrently.SubprocessRunner)43 assert inspect.isclass(alphatwirl.concurrently.WorkingArea)44 assert inspect.isclass(alphatwirl.concurrently.HTCondorJobSubmitter)45 assert inspect.isclass(alphatwirl.configure.TableConfigCompleter)46 assert inspect.isclass(alphatwirl.configure.TableFileNameComposer)47 assert inspect.isclass(alphatwirl.roottree.Branch)48 assert inspect.isclass(alphatwirl.roottree.Events)49 assert inspect.isclass(alphatwirl.summary.Reader)50 assert inspect.isclass(alphatwirl.summary.Count)51 assert inspect.isclass(alphatwirl.summary.NextKeyComposer)52 assert inspect.isclass(alphatwirl.loop.Collector)53 assert inspect.isclass(alphatwirl.loop.CollectorComposite)54 assert inspect.isclass(alphatwirl.loop.DatasetIntoEventBuildersSplitter)55 assert inspect.isclass(alphatwirl.loop.EventLoop)56 assert inspect.isclass(alphatwirl.loop.EventLoopRunner)57 assert inspect.isclass(alphatwirl.loop.EventsInDatasetReader)58 assert inspect.isclass(alphatwirl.loop.MPEventLoopRunner)59 assert inspect.isclass(alphatwirl.loop.NullCollector)60 assert inspect.isclass(alphatwirl.loop.ReaderComposite)61 assert inspect.isclass(alphatwirl.summary.BackrefMultipleArrayReader)62 assert inspect.isclass(alphatwirl.summary.Count)63 assert inspect.isclass(alphatwirl.summary.KeyValueComposer)64 assert inspect.isclass(alphatwirl.summary.NextKeyComposer)65 assert inspect.isclass(alphatwirl.summary.Reader)66 assert inspect.isclass(alphatwirl.summary.Scan)67 assert inspect.isclass(alphatwirl.summary.Sum)68 assert inspect.isclass(alphatwirl.summary.Summarizer)69 assert inspect.isclass(alphatwirl.summary.WeightCalculatorOne)...
__init__.py
Source:__init__.py
1from frame_decoder import FrameDecoder2from beacon_factory import BeaconFrameFactory3from downlink_frame_factory import DownlinkFrameFactory, ResponseFrame, response_frame4from exception import MultipleMatchingFrameTypes, NoMatchingFrameType5from devices.comm_beacon import BeaconFrame6import inspect78from pong import *9from operation import *10from program_upload import *11from fdir import *12from period_message import *13from persistent_state import *14from compile_info import *15from common import *16from suns import *17from disable_overheat_submode import *18from sail_experiment import *19from set_bitrate import *20from adcs import *21from stop_sail_deployment import *22from stop_antenna_deployment import *23from memory import *24from file_system import *25from comm import *26from time import *2728frame_types = []29frame_types += map(lambda t: t[1], inspect.getmembers(pong, predicate=inspect.isclass))30frame_types += map(lambda t: t[1], inspect.getmembers(operation, predicate=inspect.isclass))31frame_types += map(lambda t: t[1], inspect.getmembers(common, predicate=inspect.isclass))32frame_types += map(lambda t: t[1], inspect.getmembers(program_upload, predicate=inspect.isclass))33frame_types += map(lambda t: t[1], inspect.getmembers(fdir, predicate=inspect.isclass))34frame_types += map(lambda t: t[1], inspect.getmembers(period_message, predicate=inspect.isclass))35frame_types += map(lambda t: t[1], inspect.getmembers(persistent_state, predicate=inspect.isclass))36frame_types += map(lambda t: t[1], inspect.getmembers(compile_info, predicate=inspect.isclass))37frame_types += map(lambda t: t[1], inspect.getmembers(disable_overheat_submode, predicate=inspect.isclass))38frame_types += map(lambda t: t[1], inspect.getmembers(suns, predicate=inspect.isclass))39frame_types += map(lambda t: t[1], inspect.getmembers(sail_experiment, predicate=inspect.isclass))40frame_types += map(lambda t: t[1], inspect.getmembers(set_bitrate, predicate=inspect.isclass))41frame_types += map(lambda t: t[1], inspect.getmembers(adcs, predicate=inspect.isclass))42frame_types += map(lambda t: t[1], inspect.getmembers(stop_sail_deployment, predicate=inspect.isclass))43frame_types += map(lambda t: t[1], inspect.getmembers(memory, predicate=inspect.isclass))44frame_types += map(lambda t: t[1], inspect.getmembers(file_system, predicate=inspect.isclass))45frame_types += map(lambda t: t[1], inspect.getmembers(comm, predicate=inspect.isclass))46frame_types += map(lambda t: t[1], inspect.getmembers(time, predicate=inspect.isclass))47frame_types += map(lambda t: t[1], inspect.getmembers(stop_antenna_deployment, predicate=inspect.isclass))48frame_types = filter(lambda t: issubclass(t, ResponseFrame) and t != ResponseFrame, frame_types)49frame_types = reduce(lambda t, x: t + [x] if x not in t else t, frame_types, [])5051frame_factories = [BeaconFrameFactory(), DownlinkFrameFactory(frame_types)]52 53__all__ = [54 'ResponseFrame',55 'response_frame',56 'FrameDecoder',57 'BeaconFrame',58 'MultipleMatchingFrameTypes',59 'NoMatchingFrameType',60 'frame_factories'
...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!