How to use return_none method in refurb

Best Python code snippet using refurb_python

test_sideeffects.py

Source:test_sideeffects.py Github

copy

Full Screen

1# Licensed under Apache License Version 2.0 - see LICENSE2import operator3import pickle4import sys5import pytest6from iteration_utilities import sideeffects, return_None7import helper_funcs as _hf8from helper_cls import T, toT9def raise_error_when_below10(val):10 if isinstance(val, tuple):11 if val[0].value < 10:12 raise ValueError()13 else:14 if val.value < 10:15 raise ValueError()16def test_sideeffects_empty1():17 assert list(sideeffects([], return_None)) == []18def test_sideeffects_empty2():19 assert list(sideeffects([], return_None, 0)) == []20def test_sideeffects_empty3():21 assert list(sideeffects([], return_None, 1)) == []22def test_sideeffects_empty4():23 assert list(sideeffects([], return_None, 10)) == []24def test_sideeffects_normal1():25 l = []26 assert list(sideeffects([T(1), T(2)], l.append)) == [T(1), T(2)]27 assert l == [T(1), T(2)]28def test_sideeffects_normal2():29 l = []30 assert list(sideeffects([T(1), T(2)], l.append, 0)) == [T(1), T(2)]31 assert l == [T(1), T(2)]32def test_sideeffects_normal3():33 l = []34 assert list(sideeffects([T(1), T(2)], l.append, 1)) == [T(1), T(2)]35 assert l == [(T(1), ), (T(2), )]36def test_sideeffects_normal4():37 l = []38 assert list(sideeffects([T(1), T(2)], l.append, 2)) == [T(1), T(2)]39 assert l == [(T(1), T(2))]40def test_sideeffects_normal5():41 l = []42 assert list(sideeffects([T(1), T(2), T(3)], l.append,43 times=2)) == [T(1), T(2), T(3)]44 assert l == [(T(1), T(2)), (T(3), )]45def test_sideeffects_normal6():46 # generator47 l = []48 assert list(sideeffects((i for i in [T(1), T(2)]),49 l.append, 2)) == [T(1), T(2)]50 assert l == [(T(1), T(2))]51def test_sideeffects_normal7():52 # useless side-effect53 assert list(sideeffects([T(1), T(2)], return_None)) == [T(1), T(2)]54def test_sideeffects_normal8():55 # useless side-effect56 assert list(sideeffects(toT(range(10)), return_None, 3)) == toT(range(10))57def test_sideeffects_attribute1():58 it = sideeffects(toT(range(10)), return_None)59 assert it.times == 060 assert it.func is return_None61 assert it.count == 062def test_sideeffects_failure1():63 l = []64 with pytest.raises(_hf.FailIter.EXC_TYP, match=_hf.FailIter.EXC_MSG):65 sideeffects(_hf.FailIter(), l.append)66def test_sideeffects_failure2():67 l = []68 with pytest.raises(_hf.FailIter.EXC_TYP, match=_hf.FailIter.EXC_MSG):69 sideeffects(_hf.FailIter(), l.append, 1)70def test_sideeffects_failure3():71 with pytest.raises(ValueError):72 list(sideeffects([T(1), T(2), T(3)], raise_error_when_below10))73def test_sideeffects_failure4():74 with pytest.raises(ValueError):75 list(sideeffects([T(11), T(12), T(3)], raise_error_when_below10))76def test_sideeffects_failure5():77 with pytest.raises(ValueError):78 list(sideeffects([T(11), T(12), T(3)], raise_error_when_below10, 2))79def test_sideeffects_failure6():80 with pytest.raises(ValueError):81 list(sideeffects([T(3), T(12), T(11)], raise_error_when_below10, 2))82def test_sideeffects_failure7():83 # Test that a failing iterator doesn't raise a SystemError84 with pytest.raises(_hf.FailNext.EXC_TYP, match=_hf.FailNext.EXC_MSG):85 list(sideeffects(_hf.FailNext(), lambda x: x))86def test_sideeffects_failure8():87 # Too few arguments88 with pytest.raises(TypeError):89 sideeffects()90def test_sideeffects_copy1():91 _hf.iterator_copy(sideeffects(toT([1, 2, 3, 4]), return_None))92def test_sideeffects_failure_setstate1():93 # If times==0 then the second argument must be None94 se = sideeffects([T(1), T(2), T(3), T(4)], return_None)95 with pytest.raises(TypeError):96 se.__setstate__((0, ()))97def test_sideeffects_failure_setstate2():98 # The first argument must be smaller than the length of the second99 se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1)100 with pytest.raises(ValueError):101 se.__setstate__((1, (T(1), )))102def test_sideeffects_failure_setstate3():103 # The first argument must not be smaller than zero104 se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1)105 with pytest.raises(ValueError):106 se.__setstate__((-1, (T(1), )))107def test_sideeffects_failure_setstate4():108 # The length of the second argument must be equal to the "times".109 se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1)110 with pytest.raises(ValueError):111 se.__setstate__((1, (T(1), T(2))))112def test_sideeffects_failure_setstate5():113 # If the second argument is None then the times must be zero114 se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1)115 with pytest.raises(TypeError):116 se.__setstate__((0, None))117def test_sideeffects_failure_setstate6():118 # If the second argument is None then the first argument must be zero119 se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 0)120 with pytest.raises(TypeError):121 se.__setstate__((1, None))122def test_sideeffects_failure_setstate7():123 # The second argument must be a tuple or None124 se = sideeffects([T(1), T(2), T(3), T(4)], return_None, 2)125 with pytest.raises(TypeError):126 se.__setstate__((1, [T(1), T(2)]))127def test_sideeffects_failure_setstate8():128 _hf.iterator_setstate_list_fail(129 sideeffects([T(1), T(2), T(3), T(4)], return_None, 2))130def test_sideeffects_failure_setstate9():131 _hf.iterator_setstate_empty_fail(132 sideeffects([T(1), T(2), T(3), T(4)], return_None, 2))133def test_sideeffects_pickle1(protocol):134 suc = sideeffects([T(1), T(2), T(3), T(4)], return_None)135 assert next(suc) == T(1)136 x = pickle.dumps(suc, protocol=protocol)137 assert list(pickle.loads(x)) == [T(2), T(3), T(4)]138def test_sideeffects_pickle2(protocol):139 suc = sideeffects([T(1), T(2), T(3), T(4)], return_None)140 x = pickle.dumps(suc, protocol=protocol)141 assert list(pickle.loads(x)) == [T(1), T(2), T(3), T(4)]142def test_sideeffects_pickle3(protocol):143 suc = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1)144 x = pickle.dumps(suc, protocol=protocol)145 assert list(pickle.loads(x)) == [T(1), T(2), T(3), T(4)]146def test_sideeffects_pickle4(protocol):147 suc = sideeffects([T(1), T(2), T(3), T(4)], return_None, 1)148 assert next(suc) == T(1)149 x = pickle.dumps(suc, protocol=protocol)150 assert list(pickle.loads(x)) == [T(2), T(3), T(4)]151def test_sideeffects_pickle5(protocol):152 suc = sideeffects([T(1), T(2), T(3), T(4)], return_None, 2)153 assert next(suc) == T(1)154 x = pickle.dumps(suc, protocol=protocol)155 assert list(pickle.loads(x)) == [T(2), T(3), T(4)]156def test_sideeffects_pickle6(protocol):157 suc = sideeffects([T(1), T(2), T(3), T(4)], return_None, 2)158 assert next(suc) == T(1)159 assert next(suc) == T(2)160 x = pickle.dumps(suc, protocol=protocol)161 assert list(pickle.loads(x)) == [T(3), T(4)]162def test_sideeffects_lengthhint1():163 it = sideeffects([1, 2, 3, 4, 5, 6], return_None)164 _hf.check_lengthhint_iteration(it, 6)165def test_sideeffects_failure_lengthhint1():166 f_it = _hf.FailLengthHint(toT([1, 2, 3]))167 it = sideeffects(f_it, return_None)168 with pytest.raises(_hf.FailLengthHint.EXC_TYP, match=_hf.FailLengthHint.EXC_MSG):169 operator.length_hint(it)170 with pytest.raises(_hf.FailLengthHint.EXC_TYP, match=_hf.FailLengthHint.EXC_MSG):171 list(it)172def test_sideeffects_failure_lengthhint2():173 # This only checks for overflow if the length_hint is above PY_SSIZE_T_MAX174 of_it = _hf.OverflowLengthHint(toT([1, 2, 3]), sys.maxsize + 1)175 it = sideeffects(of_it, return_None)176 with pytest.raises(OverflowError):177 operator.length_hint(it)178 with pytest.raises(OverflowError):...

Full Screen

Full Screen

info_container.py

Source:info_container.py Github

copy

Full Screen

1import pprint2class InfoContainer:3 def __init__(self, items, return_none=False):4 self.__items = []5 self.__data = items6 self.return_none = return_none7 if isinstance(items, dict):8 self.__items.append({})9 for key, value in items.items():10 self.__items[0][key] = self._convert_to_info_container_if_needed(value)11 if isinstance(items, (list, tuple)):12 for value in items:13 self.__items.append(self._convert_to_info_container_if_needed(value))14 def data(self):15 return self.__data16 def is_list(self):17 return len(self.__items) > 0 and isinstance(self.__items[0], self.__class__)18 def _convert_to_info_container_if_needed(self, value):19 if isinstance(value, dict):20 return self.__class__(value, return_none=self.return_none)21 if isinstance(value, (list, tuple)):22 return [self._convert_to_info_container_if_needed(elem) for elem in value]23 return value24 def __eq__(self, other):25 return (isinstance(other, self.__class__) and self.__dict__ == other.__dict__)26 def __ne__(self, other):27 return not self.__eq__(other)28 def __repr__(self):29 return pprint.pformat(self.__dict__)30 def __getitem__(self, key):31 if isinstance(key, int):32 return self.__items[key]33 return self.__items[0][key]34 def __len__(self):35 return len(self.__items)36 def __getattribute__(self, name):37 try:38 return object.__getattribute__(self, name)39 except AttributeError:40 try:41 return self.__items[0][name]42 except KeyError:43 if self.return_none:44 return None45 raise AttributeError(name)46 def __getstate__(self):47 return self.__dict__48 def __setstate__(self, state):...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1import ui.lang_buttons as lb2from ui.utils import search_bd3def type_view(type, lang, return_none=False):4 if type is None:5 if return_none:6 return lb.both[lang]7 elif type == 0:8 return lb.flat[lang]9 elif type == 1:10 return lb.room[lang]11def city_view(city, db, lang, return_none=False):12 if not city:13 if return_none:14 return lb.none_[lang]15 else:16 return search_bd(city, db.cities)17def district_view(district, db, lang, return_none=False):18 if not district:19 if return_none:20 return lb.none_[lang]21 else:22 return search_bd(district, db.districts)23def sex_view(sex, lang, return_none=False):24 if sex == 0:25 return lb.both[lang]26 elif sex == 1:27 return lb.male[lang]28 elif sex == 2:29 return lb.female[lang]30 elif sex == 3:31 return lb.couple[lang]32 else:33 if return_none:34 return lb.none_[lang]35def owner_view(owner, lang, return_none=False):36 if owner:37 return lb.landlord_botton[lang]38 else:39 if owner is False:40 return lb.agent_botton[lang]41 if owner is None:42 if return_none:43 return lb.agent_botton[lang]44def yes_or_no(parameter, lang):45 if parameter:46 return lb.yes[lang]47 else:48 if parameter is False:...

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 refurb 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