Best Python code snippet using assertpy_python
test_summary.py
Source:test_summary.py
1# -*- coding: UTF-8 -*-2from __future__ import absolute_import, division3from mock import Mock, patch4from nose.tools import *5from behave.model import ScenarioOutline, Scenario6from behave.reporter.summary import SummaryReporter, format_summary7class TestFormatStatus(object):8 def test_passed_entry_contains_label(self):9 summary = {10 'passed': 1,11 'skipped': 0,12 'failed': 0,13 'undefined': 0,14 }15 assert format_summary('fnord', summary).startswith('1 fnord passed')16 def test_passed_entry_is_pluralised(self):17 summary = {18 'passed': 10,19 'skipped': 0,20 'failed': 0,21 'undefined': 0,22 }23 assert format_summary('fnord', summary).startswith('10 fnords passed')24 def test_remaining_fields_are_present(self):25 summary = {26 'passed': 10,27 'skipped': 1,28 'failed': 2,29 'undefined': 3,30 }31 output = format_summary('fnord', summary)32 assert '1 skipped' in output33 assert '2 failed' in output34 assert '3 undefined' in output35 def test_missing_fields_are_not_present(self):36 summary = {37 'passed': 10,38 'skipped': 1,39 'failed': 2,40 }41 output = format_summary('fnord', summary)42 assert '1 skipped' in output43 assert '2 failed' in output44 assert 'undefined' not in output45class TestSummaryReporter(object):46 @patch('sys.stdout')47 def test_duration_is_totalled_up_and_outputted(self, stdout):48 features = [Mock(), Mock(), Mock(), Mock()]49 features[0].duration = 1.950 features[0].status = 'passed'51 features[0].__iter__ = Mock(return_value=iter([]))52 features[1].duration = 2.753 features[1].status = 'passed'54 features[1].__iter__ = Mock(return_value=iter([]))55 features[2].duration = 3.556 features[2].status = 'passed'57 features[2].__iter__ = Mock(return_value=iter([]))58 features[3].duration = 4.359 features[3].status = 'passed'60 features[3].__iter__ = Mock(return_value=iter([]))61 config = Mock()62 reporter = SummaryReporter(config)63 [reporter.feature(f) for f in features]64 eq_(round(reporter.duration, 3), 12.400)65 reporter.end()66 output = stdout.write.call_args_list[-1][0][0]67 minutes = int(reporter.duration / 60.0)68 seconds = reporter.duration % 6069 assert '%dm' % (minutes,) in output70 assert '%02.1f' % (seconds,) in output71 @patch('sys.stdout')72 @patch('behave.reporter.summary.format_summary')73 def test_feature_status_is_collected_and_reported(self, format_summary,74 stdout):75 features = [Mock(), Mock(), Mock(), Mock(), Mock()]76 features[0].duration = 1.977 features[0].status = 'passed'78 features[0].__iter__ = Mock(return_value=iter([]))79 features[1].duration = 2.780 features[1].status = 'failed'81 features[1].__iter__ = Mock(return_value=iter([]))82 features[2].duration = 3.583 features[2].status = 'skipped'84 features[2].__iter__ = Mock(return_value=iter([]))85 features[3].duration = 4.386 features[3].status = 'passed'87 features[3].__iter__ = Mock(return_value=iter([]))88 features[4].duration = 5.189 features[4].status = None90 features[4].__iter__ = Mock(return_value=iter([]))91 config = Mock()92 reporter = SummaryReporter(config)93 [reporter.feature(f) for f in features]94 reporter.end()95 expected = {96 'passed': 2,97 'failed': 1,98 'skipped': 2,99 'untested': 0,100 }101 eq_(format_summary.call_args_list[0][0], ('feature', expected))102 @patch('sys.stdout')103 @patch('behave.reporter.summary.format_summary')104 def test_scenario_status_is_collected_and_reported(self, format_summary,105 stdout):106 feature = Mock()107 scenarios = [Mock(), Mock(), Mock(), Mock(), Mock()]108 scenarios[0].status = 'failed'109 scenarios[0].__iter__ = Mock(return_value=iter([]))110 scenarios[1].status = 'failed'111 scenarios[1].__iter__ = Mock(return_value=iter([]))112 scenarios[2].status = 'skipped'113 scenarios[2].__iter__ = Mock(return_value=iter([]))114 scenarios[3].status = 'passed'115 scenarios[3].__iter__ = Mock(return_value=iter([]))116 scenarios[4].status = None117 scenarios[4].__iter__ = Mock(return_value=iter([]))118 feature.status = 'failed'119 feature.duration = 12.3120 feature.__iter__ = Mock(return_value=iter(scenarios))121 config = Mock()122 reporter = SummaryReporter(config)123 reporter.feature(feature)124 reporter.end()125 expected = {126 'passed': 1,127 'failed': 2,128 'skipped': 2,129 'untested': 0,130 }131 eq_(format_summary.call_args_list[1][0], ('scenario', expected))132 @patch('behave.reporter.summary.format_summary')133 @patch('sys.stdout')134 def test_scenario_outline_status_is_collected_and_reported(self, stdout,135 format_summary):136 feature = Mock()137 scenarios = [ ScenarioOutline(u"<string>", 0, u"scenario_outline", u"name"),138 Mock(), Mock(), Mock() ]139 subscenarios = [ Mock(), Mock(), Mock(), Mock() ]140 subscenarios[0].status = 'passed'141 subscenarios[0].__iter__ = Mock(return_value=iter([]))142 subscenarios[1].status = 'failed'143 subscenarios[1].__iter__ = Mock(return_value=iter([]))144 subscenarios[2].status = 'failed'145 subscenarios[2].__iter__ = Mock(return_value=iter([]))146 subscenarios[3].status = 'skipped'147 subscenarios[3].__iter__ = Mock(return_value=iter([]))148 scenarios[0]._scenarios = subscenarios149 scenarios[1].status = 'failed'150 scenarios[1].__iter__ = Mock(return_value=iter([]))151 scenarios[2].status = 'skipped'152 scenarios[2].__iter__ = Mock(return_value=iter([]))153 scenarios[3].status = 'passed'154 scenarios[3].__iter__ = Mock(return_value=iter([]))155 feature.status = 'failed'156 feature.duration = 12.4157 feature.__iter__ = Mock(return_value=iter(scenarios))158 config = Mock()159 reporter = SummaryReporter(config)160 reporter.feature(feature)161 reporter.end()162 expected = {163 'passed': 2,164 'failed': 3,165 'skipped': 2,166 'untested': 0,167 }168 eq_(format_summary.call_args_list[1][0], ('scenario', expected))169 @patch('sys.stdout')170 @patch('behave.reporter.summary.format_summary')171 def test_step_status_is_collected_and_reported(self, format_summary,172 stdout):173 feature = Mock()174 scenario = Mock()175 steps = [Mock(), Mock(), Mock(), Mock(), Mock()]176 steps[0].status = 'failed'177 steps[0].__iter__ = Mock(return_value=iter([]))178 steps[1].status = 'undefined'179 steps[1].__iter__ = Mock(return_value=iter([]))180 steps[2].status = 'passed'181 steps[2].__iter__ = Mock(return_value=iter([]))182 steps[3].status = 'passed'183 steps[3].__iter__ = Mock(return_value=iter([]))184 steps[4].status = None185 steps[4].__iter__ = Mock(return_value=iter([]))186 feature.status = 'failed'187 feature.duration = 12.3188 feature.__iter__ = Mock(return_value=iter([scenario]))189 scenario.status = 'failed'190 scenario.__iter__ = Mock(return_value=iter(steps))191 config = Mock()192 reporter = SummaryReporter(config)193 reporter.feature(feature)194 reporter.end()195 expected = {196 'passed': 2,197 'failed': 1,198 'skipped': 1,199 'untested': 0,200 'undefined': 1,201 }...
itertools.py
Source:itertools.py
1import __builtin__23class chain(__builtin__.object):4 def __getattribute__(): pass5 def __iter__(): pass6 def next(): pass7 __new__ = 08 from_iterable = 09 10class combinations(__builtin__.object):11 def __getattribute__(): pass12 def __iter__(): pass13 def next(): pass14 __new__ = 015 16class combinations_with_replacement(__builtin__.object):17 def __getattribute__(): pass18 def __iter__(): pass19 def next(): pass20 __new__ = 021 22class compress(__builtin__.object):23 def __getattribute__(): pass24 def __iter__(): pass25 def next(): pass26 __new__ = 027 28class count(__builtin__.object):29 def __getattribute__(): pass30 def __iter__(): pass31 def __reduce__(): pass32 def __repr__(): pass33 def next(): pass34 __new__ = 035 36class cycle(__builtin__.object):37 def __getattribute__(): pass38 def __iter__(): pass39 def next(): pass40 __new__ = 041 42class dropwhile(__builtin__.object):43 def __getattribute__(): pass44 def __iter__(): pass45 def next(): pass46 __new__ = 047 48class groupby(__builtin__.object):49 def __getattribute__(): pass50 def __iter__(): pass51 def next(): pass52 __new__ = 053 54class ifilter(__builtin__.object):55 def __getattribute__(): pass56 def __iter__(): pass57 def next(): pass58 __new__ = 059 60class ifilterfalse(__builtin__.object):61 def __getattribute__(): pass62 def __iter__(): pass63 def next(): pass64 __new__ = 065 66class imap(__builtin__.object):67 def __getattribute__(): pass68 def __iter__(): pass69 def next(): pass70 __new__ = 071 72class islice(__builtin__.object):73 def __getattribute__(): pass74 def __iter__(): pass75 def next(): pass76 __new__ = 077 78class izip(__builtin__.object):79 def __getattribute__(): pass80 def __iter__(): pass81 def next(): pass82 __new__ = 083 84class izip_longest(__builtin__.object):85 def __getattribute__(): pass86 def __iter__(): pass87 def next(): pass88 __new__ = 089 90class permutations(__builtin__.object):91 def __getattribute__(): pass92 def __iter__(): pass93 def next(): pass94 __new__ = 095 96class product(__builtin__.object):97 def __getattribute__(): pass98 def __iter__(): pass99 def next(): pass100 __new__ = 0101 102class repeat(__builtin__.object):103 def __getattribute__(): pass104 def __iter__(): pass105 def __length_hint__(): pass106 def __repr__(): pass107 def next(): pass108 __new__ = 0109 110class starmap(__builtin__.object):111 def __getattribute__(): pass112 def __iter__(): pass113 def next(): pass114 __new__ = 0115 116class takewhile(__builtin__.object):117 def __getattribute__(): pass118 def __iter__(): pass119 def next(): pass120 __new__ = 0121122def tee(): pass123
...
non_iterator_returned.py
Source:non_iterator_returned.py
2# pylint: disable=too-few-public-methods, missing-docstring, no-self-use, useless-object-inheritance3import six4class FirstGoodIterator(object):5 """ yields in iterator. """6 def __iter__(self):7 for index in range(10):8 yield index9class SecondGoodIterator(object):10 """ __iter__ and next """11 def __iter__(self):12 return self13 def __next__(self):14 """ Infinite iterator, but still an iterator """15 return 116 def next(self):17 """Same as __next__, but for Python 2."""18 return 119class ThirdGoodIterator(object):20 """ Returns other iterator, not the current instance """21 def __iter__(self):22 return SecondGoodIterator()23class FourthGoodIterator(object):24 """ __iter__ returns iter(...) """25 def __iter__(self):26 return iter(range(10))27class IteratorMetaclass(type):28 def __next__(cls):29 return 130 def next(cls):31 return 232@six.add_metaclass(IteratorMetaclass)33class IteratorClass(object):34 """Iterable through the metaclass."""35class FifthGoodIterator(object):36 """__iter__ returns a class which uses an iterator-metaclass."""37 def __iter__(self):38 return IteratorClass39class FileBasedIterator(object):40 def __init__(self, path):41 self.path = path42 self.file = None43 def __iter__(self):44 if self.file is not None:45 self.file.close()46 self.file = open(self.path)47 # self file has two infered values: None and <instance of 'file'>48 # we don't want to emit error in this case49 return self.file50class FirstBadIterator(object):51 """ __iter__ returns a list """52 def __iter__(self): # [non-iterator-returned]53 return []54class SecondBadIterator(object):55 """ __iter__ without next """56 def __iter__(self): # [non-iterator-returned]57 return self58class ThirdBadIterator(object):59 """ __iter__ returns an instance of another non-iterator """60 def __iter__(self): # [non-iterator-returned]61 return SecondBadIterator()62class FourthBadIterator(object):63 """__iter__ returns a class."""64 def __iter__(self): # [non-iterator-returned]...
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!!