How to use assert_isinstance method in Testify

Best Python code snippet using Testify_python

dimensionality.py

Source:dimensionality.py Github

copy

Full Screen

...7import numpy as np8from . import markup9from .registry import unit_registry10from .decorators import memoize11def assert_isinstance(obj, types):12 try:13 assert isinstance(obj, types)14 except AssertionError:15 raise TypeError(16 "arg %r must be of type %r, got %r" % (obj, types, type(obj))17 )18class Dimensionality(dict):19 """20 """21 @property22 def ndims(self):23 return sum(abs(i) for i in self.simplified.values())24 @property25 def simplified(self):26 if len(self):27 rq = 1*unit_registry['dimensionless']28 for u, d in self.items():29 rq = rq * u.simplified**d30 return rq.dimensionality31 else:32 return self33 @property34 def string(self):35 return markup.format_units(self)36 @property37 def unicode(self):38 return markup.format_units_unicode(self)39 40 @property41 def latex(self):42 return markup.format_units_latex(self)43 def __hash__(self):44 res = hash(unit_registry['dimensionless'])45 for key in sorted(self.keys(), key=operator.attrgetter('format_order')):46 val = self[key]47 if val < 0:48 # can you believe that hash(-1)==hash(-2)?49 val -= 150 res ^= hash((key, val))51 return res52 def __add__(self, other):53 assert_isinstance(other, Dimensionality)54 try:55 assert self == other56 except AssertionError:57 raise ValueError(58 'can not add units of %s and %s'\59 %(str(self), str(other))60 )61 return self.copy()62 __radd__ = __add__63 def __iadd__(self, other):64 assert_isinstance(other, Dimensionality)65 try:66 assert self == other67 except AssertionError:68 raise ValueError(69 'can not add units of %s and %s'\70 %(str(self), str(other))71 )72 return self73 def __sub__(self, other):74 assert_isinstance(other, Dimensionality)75 try:76 assert self == other77 except AssertionError:78 raise ValueError(79 'can not subtract units of %s and %s'\80 %(str(self), str(other))81 )82 return self.copy()83 __rsub__ = __sub__84 def __isub__(self, other):85 assert_isinstance(other, Dimensionality)86 try:87 assert self == other88 except AssertionError:89 raise ValueError(90 'can not add units of %s and %s'\91 %(str(self), str(other))92 )93 return self94 def __mul__(self, other):95 assert_isinstance(other, Dimensionality)96 new = Dimensionality(self)97 for unit, power in other.items():98 try:99 new[unit] += power100 if new[unit] == 0:101 new.pop(unit)102 except KeyError:103 new[unit] = power104 return new105 def __imul__(self, other):106 assert_isinstance(other, Dimensionality)107 for unit, power in other.items():108 try:109 self[unit] += power110 if self[unit] == 0:111 self.pop(unit)112 except KeyError:113 self[unit] = power114 return self115 def __truediv__(self, other):116 assert_isinstance(other, Dimensionality)117 new = Dimensionality(self)118 for unit, power in other.items():119 try:120 new[unit] -= power121 if new[unit] == 0:122 new.pop(unit)123 except KeyError:124 new[unit] = -power125 return new126 if sys.version_info[0] < 3:127 def __div__(self, other):128 assert_isinstance(other, Dimensionality)129 return self.__truediv__(other)130 def __itruediv__(self, other):131 assert_isinstance(other, Dimensionality)132 for unit, power in other.items():133 try:134 self[unit] -= power135 if self[unit] == 0:136 self.pop(unit)137 except KeyError:138 self[unit] = -power139 return self140 if sys.version_info[0] < 3:141 def __idiv__(self, other):142 assert_isinstance(other, Dimensionality)143 return self.__itruediv__(other)144 def __pow__(self, other):145 try:146 assert np.isscalar(other)147 except AssertionError:148 raise TypeError('exponent must be a scalar, got %r' % other)149 if other == 0:150 return Dimensionality()151 new = Dimensionality(self)152 for i in new:153 new[i] *= other154 return new155 def __ipow__(self, other):156 try:...

Full Screen

Full Screen

plotting_test.py

Source:plotting_test.py Github

copy

Full Screen

...15 times, # can't rename this or else the others can't find it16 normalized_daily as soiling_normalized_daily,17 insolation as soiling_insolation,18)19def assert_isinstance(obj, klass):20 assert isinstance(obj, klass), f'got {type(obj)}, expected {klass}'21# can't import degradation fixtures because it's a unittest file.22# roll our own here instead:23@pytest.fixture()24def degradation_power_signal():25 ''' Returns a clean offset sinusoidal with exponential degradation '''26 idx = pd.date_range('2017-01-01', '2020-01-01', freq='d', tz='UTC')27 annual_rd = -0.00528 daily_rd = 1 - (1 - annual_rd)**(1/365)29 day_count = np.arange(0, len(idx))30 degradation_derate = (1 + daily_rd) ** day_count31 power = 1 - 0.1*np.cos(day_count/365 * 2*np.pi)32 power *= degradation_derate33 power = pd.Series(power, index=idx)34 return power35@pytest.fixture()36def degradation_info(degradation_power_signal):37 '''38 Return results of running YoY degradation on raw power.39 Note: no normalization needed since power is ~(1.0 + seasonality + deg)40 Returns41 -------42 power_signal : pd.Series43 degradation_rate : float44 confidence_interval : np.array of length 245 calc_info : dict with keys:46 ['YoY_values', 'renormalizing_factor', 'exceedance_level']47 '''48 rd, rd_ci, calc_info = degradation_year_on_year(degradation_power_signal)49 return degradation_power_signal, rd, rd_ci, calc_info50def test_degradation_summary_plots(degradation_info):51 power, yoy_rd, yoy_ci, yoy_info = degradation_info52 # test defaults53 result = degradation_summary_plots(yoy_rd, yoy_ci, yoy_info, power)54 assert_isinstance(result, plt.Figure)55def test_degradation_summary_plots_kwargs(degradation_info):56 power, yoy_rd, yoy_ci, yoy_info = degradation_info57 # test kwargs58 kwargs = dict(59 hist_xmin=-1,60 hist_xmax=1,61 bins=100,62 scatter_ymin=0,63 scatter_ymax=1,64 plot_color='g',65 summary_title='test',66 scatter_alpha=1.0,67 )68 result = degradation_summary_plots(yoy_rd, yoy_ci, yoy_info, power,69 **kwargs)70 assert_isinstance(result, plt.Figure)71@pytest.fixture()72def soiling_info(soiling_normalized_daily, soiling_insolation):73 '''74 Return results of running soiling_srr.75 Returns76 -------77 calc_info : dict with keys:78 ['renormalizing_factor', 'exceedance_level',79 'stochastic_soiling_profiles', 'soiling_interval_summary',80 'soiling_ratio_perfect_clean']81 '''82 reps = 1083 np.random.seed(1977)84 sr, sr_ci, calc_info = soiling_srr(soiling_normalized_daily,85 soiling_insolation,86 reps=reps)87 return calc_info88def test_soiling_monte_carlo_plot(soiling_normalized_daily, soiling_info):89 # test defaults90 result = soiling_monte_carlo_plot(soiling_info, soiling_normalized_daily)91 assert_isinstance(result, plt.Figure)92def test_soiling_monte_carlo_plot_kwargs(soiling_normalized_daily, soiling_info):93 # test kwargs94 kwargs = dict(95 point_alpha=0.1,96 profile_alpha=0.4,97 ymin=0,98 ymax=1,99 profiles=5,100 point_color='k',101 profile_color='b',102 )103 result = soiling_monte_carlo_plot(soiling_info, soiling_normalized_daily,104 **kwargs)105 assert_isinstance(result, plt.Figure)106def test_soiling_interval_plot(soiling_normalized_daily, soiling_info):107 # test defaults108 result = soiling_interval_plot(soiling_info, soiling_normalized_daily)109 assert_isinstance(result, plt.Figure)110def test_soiling_interval_plot_kwargs(soiling_normalized_daily, soiling_info):111 # test kwargs112 kwargs = dict(113 point_alpha=0.1,114 profile_alpha=0.5,115 ymin=0,116 ymax=1,117 point_color='k',118 profile_color='g',119 )120 result = soiling_interval_plot(soiling_info, soiling_normalized_daily,121 **kwargs)122 assert_isinstance(result, plt.Figure)123def test_soiling_rate_histogram(soiling_info):124 # test defaults125 result = soiling_rate_histogram(soiling_info)126 assert_isinstance(result, plt.Figure)127def test_soiling_rate_histogram_kwargs(soiling_info):128 # test kwargs129 kwargs = dict(130 bins=10,131 )132 result = soiling_rate_histogram(soiling_info, **kwargs)...

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