How to use test_when method in Kiwi

Best Python code snippet using Kiwi_python

test_solar.py

Source:test_solar.py Github

copy

Full Screen

1#!/usr/bin/python32# Library for calculating location of the sun3# Copyright Brandon Stafford4#5# This file is part of Pysolar.6#7# Pysolar is free software; you can redistribute it and/or modify8# it under the terms of the GNU General Public License as published by9# the Free Software Foundation; either version 3 of the License, or10# (at your option) any later version.11#12# Pysolar is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15# GNU General Public License for more details.16#17# You should have received a copy of the GNU General Public License along18# with Pysolar. If not, see <http://www.gnu.org/licenses/>.19from pysolar import \20 solar, \21 constants, \22 solartime as stime, \23 elevation24import datetime25import unittest26class TestSolar(unittest.TestCase):27 def setUp(self):28 self.d = datetime.datetime(2003, 10, 17, 19, 30, 30, tzinfo = datetime.timezone.utc) # only works with Python 329 self.d += datetime.timedelta(seconds = stime.get_delta_t(self.d) - stime.tt_offset - stime.get_leap_seconds(self.d))30 # Reda & Andreas say that this time is in "Local Standard Time", which they31 # define as 7 hours behind UT (not UTC). Hence the adjustment to convert UT32 # to UTC.33 self.longitude = -105.178634 self.latitude = 39.74247635 self.pressure = 82000.0 # pascals36 self.elevation = 1830.14 # meters37 self.temperature = 11.0 + constants.celsius_offset # kelvin38 self.slope = 30.0 # degrees39 self.slope_orientation = -10.0 # degrees east from south40 self.jd = stime.get_julian_solar_day(self.d)41 self.jc = stime.get_julian_century(self.jd)42 self.jde = stime.get_julian_ephemeris_day(self.d)43 self.jce = stime.get_julian_ephemeris_century(self.jde)44 self.jme = stime.get_julian_ephemeris_millennium(self.jce)45 self.geocentric_longitude = solar.get_geocentric_longitude(self.jme)46 self.geocentric_latitude = solar.get_geocentric_latitude(self.jme)47 self.nutation = solar.get_nutation(self.jce)48 self.sun_earth_distance = solar.get_sun_earth_distance(self.jme)49 self.true_ecliptic_obliquity = solar.get_true_ecliptic_obliquity(self.jme, self.nutation)50 self.aberration_correction = solar.get_aberration_correction(self.sun_earth_distance)51 self.apparent_sun_longitude = solar.get_apparent_sun_longitude(self.geocentric_longitude, self.nutation, self.aberration_correction)52 self.apparent_sidereal_time = solar.get_apparent_sidereal_time(self.jd, self.jme, self.nutation)53 self.geocentric_sun_right_ascension = solar.get_geocentric_sun_right_ascension(self.apparent_sun_longitude, self.true_ecliptic_obliquity, self.geocentric_latitude)54 self.geocentric_sun_declination = solar.get_geocentric_sun_declination(self.apparent_sun_longitude, self.true_ecliptic_obliquity, self.geocentric_latitude)55 self.local_hour_angle = solar.get_local_hour_angle(318.5119, self.longitude, self.geocentric_sun_right_ascension) #self.apparent_sidereal_time only correct to 5 sig figs, so override56 self.equatorial_horizontal_parallax = solar.get_equatorial_horizontal_parallax(self.sun_earth_distance)57 self.projected_radial_distance = solar.get_projected_radial_distance(self.elevation, self.latitude)58 self.projected_axial_distance = solar.get_projected_axial_distance(self.elevation, self.latitude)59 self.topocentric_sun_right_ascension = solar.get_topocentric_sun_right_ascension(self.projected_radial_distance,60 self.equatorial_horizontal_parallax, self.local_hour_angle, self.apparent_sun_longitude, self.true_ecliptic_obliquity, self.geocentric_latitude)61 self.parallax_sun_right_ascension = solar.get_parallax_sun_right_ascension(self.projected_radial_distance, self.equatorial_horizontal_parallax, self.local_hour_angle, self.geocentric_sun_declination)62 self.topocentric_sun_declination = solar.get_topocentric_sun_declination(self.geocentric_sun_declination, self.projected_axial_distance, self.equatorial_horizontal_parallax, self.parallax_sun_right_ascension, self.local_hour_angle)63 self.topocentric_local_hour_angle = solar.get_topocentric_local_hour_angle(self.local_hour_angle, self.parallax_sun_right_ascension)64 self.topocentric_zenith_angle = solar.get_topocentric_zenith_angle(self.latitude, self.topocentric_sun_declination, self.topocentric_local_hour_angle, self.pressure, self.temperature)65 self.topocentric_azimuth_angle = solar.get_topocentric_azimuth_angle(self.topocentric_local_hour_angle, self.latitude, self.topocentric_sun_declination)66 self.incidence_angle = solar.get_incidence_angle(self.topocentric_zenith_angle, self.slope, self.slope_orientation, self.topocentric_azimuth_angle)67 self.pressure_with_elevation = elevation.get_pressure_with_elevation(1567.7)68 self.temperature_with_elevation = elevation.get_temperature_with_elevation(1567.7)69 def test_get_julian_solar_day(self):70 self.assertAlmostEqual(2452930.312847, self.jd, 6) # value from Reda and Andreas (2005)71 def test_get_julian_ephemeris_day(self):72 self.assertAlmostEqual(2452930.3136, self.jde, 4) # value not validated73 def test_get_julian_century(self):74 self.assertAlmostEqual(0.03792779869191517, self.jc, 12) # value not validated75 def test_get_julian_ephemeris_millennium(self):76 self.assertAlmostEqual(0.0037927819143886397, self.jme, 12) # value not validated77 def test_get_geocentric_longitude(self):78 # self.assertAlmostEqual(204.0182635175, self.geocentric_longitude, 10) # value from Reda and Andreas (2005)79 self.assertAlmostEqual(204.0182635175, self.geocentric_longitude, 4) # above fails with more accurate Julian Ephemeris correction80 def test_get_geocentric_latitude(self):81 # self.assertAlmostEqual(0.0001011219, self.geocentric_latitude, 9) # value from Reda and Andreas (2005)82 self.assertAlmostEqual(0.0001011219, self.geocentric_latitude, 8) # above fails with more accurate Julian Ephemeris correction83 def test_get_nutation(self):84 self.assertAlmostEqual(0.00166657, self.nutation['obliquity'], 8) # value from Reda and Andreas (2005)85 self.assertAlmostEqual(-0.00399840, self.nutation['longitude'], 8) # value from Reda and Andreas (2005)86 def test_get_sun_earth_distance(self):87 self.assertAlmostEqual(0.9965421031, self.sun_earth_distance, 6) # value from Reda and Andreas (2005)88 def test_get_true_ecliptic_obliquity(self):89 self.assertAlmostEqual(23.440465, self.true_ecliptic_obliquity, 6) # value from Reda and Andreas (2005)90 def test_get_aberration_correction(self):91 self.assertAlmostEqual(-0.005711359, self.aberration_correction, 9) # value not validated92 def test_get_apparent_sun_longitude(self):93 # self.assertAlmostEqual(204.0085537528, self.apparent_sun_longitude, 10) # value from Reda and Andreas (2005)94 self.assertAlmostEqual(204.0085537528, self.apparent_sun_longitude, 4) # above fails with more accurate Julian Ephemeris correction95 def test_get_apparent_sidereal_time(self):96 self.assertAlmostEqual(318.5119, self.apparent_sidereal_time, 2) # value derived from Reda and Andreas (2005)97 def test_get_geocentric_sun_right_ascension(self):98 self.assertAlmostEqual(202.22741, self.geocentric_sun_right_ascension, 4) # value from Reda and Andreas (2005)99 def test_get_geocentric_sun_declination(self):100 self.assertAlmostEqual(-9.31434, self.geocentric_sun_declination, 4) # value from Reda and Andreas (2005)101 def test_get_local_hour_angle(self):102 self.assertAlmostEqual(11.105900, self.local_hour_angle, 4) # value from Reda and Andreas (2005)103 def test_get_projected_radial_distance(self):104 self.assertAlmostEqual(0.7702006, self.projected_radial_distance, 6) # value not validated105 def test_get_topocentric_sun_right_ascension(self):106 self.assertAlmostEqual(202.22741, self.topocentric_sun_right_ascension, 3) # value from Reda and Andreas (2005)107 def test_get_parallax_sun_right_ascension(self):108 self.assertAlmostEqual(-0.0003659912761437859, self.parallax_sun_right_ascension, 12) # value not validated109 110 def test_get_topocentric_sun_declination(self):111 self.assertAlmostEqual(-9.316179, self.topocentric_sun_declination, 3) # value from Reda and Andreas (2005)112 def test_get_topocentric_local_hour_angle(self):113 self.assertAlmostEqual(11.10629, self.topocentric_local_hour_angle, 4) # value from Reda and Andreas (2005)114 def test_get_topocentric_zenith_angle(self):115 self.assertAlmostEqual(50.11162, self.topocentric_zenith_angle, 3) # value from Reda and Andreas (2005)116 def test_get_topocentric_azimuth_angle(self):117 # self.assertAlmostEqual(194.34024, self.topocentric_azimuth_angle, 5) # value from Reda and Andreas (2005)118 self.assertAlmostEqual(194.34024, self.topocentric_azimuth_angle, 4) # above fails with more accurate Julian Ephemeris correction119 def test_get_incidence_angle(self):120 self.assertAlmostEqual(25.18700, self.incidence_angle, 3) # value from Reda and Andreas (2005)121 def testPressureWithElevation(self):122 self.assertAlmostEqual(83855.90228, self.pressure_with_elevation, 4)123 def testTemperatureWithElevation(self):124 self.assertAlmostEqual(277.9600, self.temperature_with_elevation, 4)125class TestApi(unittest.TestCase):126 test_when = datetime.datetime(2016, 12, 19, 23, 0, 0, tzinfo=datetime.timezone.utc)127 def testGetPosition(self):128 az, al = solar.get_position(59.6365662,12.5350953, TestApi.test_when)129 self.assertAlmostEqual(az, 357.1431414)130 self.assertAlmostEqual(al, -53.7672217)131 az, al = solar.get_position(-43, 172, TestApi.test_when)132 self.assertAlmostEqual(az, 50.50035708)133 self.assertAlmostEqual(al, 63.0922036)134 # From Greenwich135 az, al = solar.get_position(51.4826, 0, TestApi.test_when)136 self.assertAlmostEqual(az, 333.04037976)137 self.assertAlmostEqual(al, -59.83724345)138 def testGetAltitude(self):139 al = solar.get_altitude(-43, 172, TestApi.test_when)140 self.assertAlmostEqual(al, 63.0922036)141 def testGetAzimuth(self):142 az = solar.get_azimuth(-43, 172, TestApi.test_when)143 self.assertAlmostEqual(az, 50.50035708)144 def testGetAltitudeFast(self):145 # location is in NZ, use relevant timezone146 day = datetime.datetime(147 2016, 12, 19, 0, 0,148 tzinfo=datetime.timezone(datetime.timedelta(hours=12)))149 for hour in range(7, 19):150 when = day + datetime.timedelta(hours=hour)151 al = solar.get_altitude_fast(-43, 172, when)152 al_expected = solar.get_altitude(-43, 172, when)153 self.assertAlmostEqual(al, al_expected, delta=1)154 def testGetAzimuthFast(self):155 day = datetime.datetime(156 2016, 12, 19, 0, 0,157 tzinfo=datetime.timezone(datetime.timedelta(hours=12)))158 for hour in range(7, 19):159 when = day + datetime.timedelta(hours=hour)160 az = solar.get_azimuth_fast(-43, 172, when)161 az_expected = solar.get_azimuth(-43, 172, when)162 self.assertAlmostEqual(az, az_expected, delta=1.5)163if __name__ == "__main__":...

Full Screen

Full Screen

test_integration.py

Source:test_integration.py Github

copy

Full Screen

1# Copyright 2022 ABSA Group Limited2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import pytest15import tests.test_test_utils.test_when16from pramen_py.test_utils.when import Markers17class Klass1:18 def some_method(19 self,20 arg1: str,21 arg2: int,22 *,23 kwarg1: str,24 kwarg2: str,25 ) -> str:26 return "Not mocked"27 def some_method_with_defaults(28 self,29 arg1: str,30 arg2: int,31 *,32 kwarg1: str,33 kwarg2: str = "some default string",34 ) -> str:35 return "Not mocked"36 @classmethod37 def some_class_method(38 cls,39 arg1: str,40 arg2: int,41 *,42 kwarg1: str,43 kwarg2: str,44 ) -> str:45 return "Not mocked"46class Klass2:47 def some_method(48 self,49 arg1: str,50 arg2: int,51 *,52 kwarg1: str,53 kwarg2: str,54 ) -> str:55 return "Not mocked"56def test_should_properly_patch_calls(when):57 when(Klass1, "some_method").called_with(58 "a",59 Markers.any,60 kwarg1="b",61 kwarg2=Markers.any,62 ).then_return("Mocked")63 assert (64 Klass1().some_method(65 "a",66 1,67 kwarg1="b",68 kwarg2="c",69 )70 == "Mocked"71 )72 assert (73 Klass1().some_method(74 "not mocked param",75 1,76 kwarg1="b",77 kwarg2="c",78 )79 == "Not mocked"80 )81@pytest.mark.skip(82 reason=(83 "bug in unittest, "84 "see https://github.com/python/cpython/issues/67267"85 )86)87def test_should_work_with_classmethods(when):88 when(Klass1, "some_class_method").called_with(89 "a",90 Markers.any,91 kwarg1="b",92 kwarg2=Markers.any,93 ).then_return("Mocked")94 assert (95 Klass1().some_class_method(96 "a",97 1,98 kwarg1="b",99 kwarg2="c",100 )101 == "Mocked"102 )103 assert (104 Klass1.some_class_method(105 "not mocked param",106 1,107 kwarg1="b",108 kwarg2="c",109 )110 == "Not mocked"111 )112def test_should_work_with_normal_functions(when):113 when(tests.test_test_utils.test_when, "some_normal_function").called_with(114 "a",115 Markers.any,116 kwarg1="b",117 kwarg2=Markers.any,118 ).then_return("Mocked")119 assert (120 tests.test_test_utils.test_when.some_normal_function(121 "a",122 1,123 kwarg1="b",124 kwarg2="c",125 )126 == "Mocked"127 )128 assert (129 tests.test_test_utils.test_when.some_normal_function(130 "not mocked param",131 1,132 kwarg1="b",133 kwarg2="c",134 )135 == "Not mocked"136 )137def test_should_be_able_to_patch_multiple_calls(when):138 when(Klass1, "some_method").called_with(139 "a",140 Markers.any,141 kwarg1="b",142 kwarg2=Markers.any,143 ).then_return("Mocked first time")144 when(Klass1, "some_method").called_with(145 Markers.any,146 1,147 kwarg1=Markers.any,148 kwarg2="b",149 ).then_return("Mocked second time")150 assert (151 Klass1().some_method(152 "a",153 1,154 kwarg1="b",155 kwarg2="c",156 )157 == "Mocked first time"158 )159 assert (160 Klass1().some_method(161 "any",162 1,163 kwarg1="any too",164 kwarg2="b",165 )166 == "Mocked second time"167 )168 assert (169 Klass1().some_method(170 "not mocked param",171 1,172 kwarg1="b",173 kwarg2="c",174 )175 == "Not mocked"176 )177def test_should_be_able_to_patch_multiple_objects(when):178 when(Klass1, "some_method").called_with(179 "a",180 Markers.any,181 kwarg1="b",182 kwarg2=Markers.any,183 ).then_return("Mocked Klass1")184 when(Klass2, "some_method").called_with(185 "b",186 Markers.any,187 kwarg1="c",188 kwarg2=Markers.any,189 ).then_return("Mocked Klass2")190 assert (191 Klass1().some_method(192 "a",193 1,194 kwarg1="b",195 kwarg2="c",196 )197 == "Mocked Klass1"198 )199 assert (200 Klass1().some_method(201 "not mocked param",202 1,203 kwarg1="b",204 kwarg2="c",205 )206 == "Not mocked"207 )208 assert (209 Klass2().some_method(210 "b",211 1,212 kwarg1="c",213 kwarg2="any",214 )215 == "Mocked Klass2"216 )217 assert (218 Klass2().some_method(219 "not mocked param",220 1,221 kwarg1="b",222 kwarg2="c",223 )224 == "Not mocked"225 )226def test_should_work_with_default_params_in_functions(when):227 patched_klass = (228 when(Klass1, "some_method_with_defaults")229 .called_with(230 Markers.any,231 Markers.any,232 kwarg1=Markers.any,233 kwarg2="some default string",234 )235 .then_return("Mocked")236 )237 assert (238 Klass1().some_method_with_defaults(239 "a",240 1,241 kwarg1="b",242 )243 == "Mocked"244 )245 assert (246 Klass1().some_method(247 "not mocked param",248 1,249 kwarg1="b",250 kwarg2="c",251 )252 == "Not mocked"253 )...

Full Screen

Full Screen

test_declarative_when.py

Source:test_declarative_when.py Github

copy

Full Screen

1import os2import bspump.declarative3import bspump.unittest4class TestDeclarativeWhen(bspump.unittest.TestCase):5 def setUp(self) -> None:6 super().setUp()7 self.Builder = bspump.declarative.ExpressionBuilder(self.App)8 def load(self, decl_fname):9 basedir = os.path.dirname(__file__)10 with open(os.path.join(basedir, decl_fname), 'r') as f:11 return self.Builder.parse(f.read())[0]12 def test_when_01_else(self):13 decl = self.load('./test_when.yaml')14 res = decl({}, {'key': -1})15 self.assertEqual(res, "Unknown")16 def test_when_01_exact(self):17 decl = self.load('./test_when.yaml')18 res = decl({}, {'key': 34})19 self.assertEqual(res, "Thirty four")20 def test_when_01_range(self):21 decl = self.load('./test_when.yaml')22 res = decl({}, {'key': 45})23 self.assertEqual(res, "fourty to fifty (exclusive)")24 def test_when_01_set(self):25 decl = self.load('./test_when.yaml')26 res = decl({}, {'key': 75})...

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