How to use should_be method in Selene

Best Python code snippet using selene_python

test_atmosphere.py

Source:test_atmosphere.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2#3# Geonum is a Python library for geographical calculations in 3D4# Copyright (C) 2017 Jonas Gliss (jonasgliss@gmail.com)5#6# This program is free software: you can redistribute it and/or7# modify it under the terms of the GNU General Public License a8# published by the Free Software Foundation, either version 3 of9# the License, or (at your option) any later version.10#11# This program is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14# General Public License for more details.15#16# You should have received a copy of the GNU General Public License17# along with this program. If not, see <http://www.gnu.org/licenses/>.18"""19Module for atmospheric calculations relevant for geonum20"""21import pytest22import numpy as np23import numpy.testing as npt24from geonum import atmosphere as atm25def test_p0():26#: Pressure at sea level [Pa]27 assert atm.p0 == 101325.028def test_NA():29 #: Avogadro constant [mol-1]30 assert atm.NA == 6.022140857e+2331def test_T0_STD():32 #: Standard sea level temperature [K]33 assert atm.T0_STD == 288.1534def test_M_AIR_AVG():35 #: Average molar mass of air, Unit: [g mol-1]36 assert atm.M_AIR_AVG == 28.964537def test_R_STD():38 #: Gas constant (U.S. standard atmosphere) [Nm mol-1 K-1]39 assert atm.R_STD == 8.3143240def test_L_STD_ATM():41 #: Atmospheric lapse rate (Standard atmosphere) [K m-1]42 assert atm.L_STD_ATM == -6.5e-343def test_L_DRY_AIR():44 #: Atmospheric lapse rate (dry atmosphere) [K m-1]45 assert atm.L_DRY_AIR == -9.8e-346@pytest.mark.parametrize('phi,should_be',[47 (0, 9.780356),48 (0.79, 9.806398), #45deg49 (1.57, 9.83208), #90deg50 ])51def test__g0(phi,should_be):52 val = atm._g0(phi)53 npt.assert_allclose(val, should_be, rtol=1e-7)54@pytest.mark.parametrize('phi,alt,should_be',[55 (0, 0, 9.780356),56 (0.79, 0, 9.806398), #45deg57 (1.57, 0, 9.83208), #90deg58 (0, 1000, 9.471702),59 (0.79, 1000, 9.497973), #45deg60 (1.57, 1000, 9.523879), #90deg61 ])62def test__g_acc(phi,alt,should_be):63 val = atm._g_acc(phi,alt)64 npt.assert_allclose(val, should_be, rtol=1e-7)65@pytest.mark.parametrize('lat,alt,should_be',[66 (0, 0, 9.780356),67 (45, 0, 9.80616), #45deg68 (90, 0, 9.83208), #90deg69 (0, 1000, 9.471702),70 (45, 1000, 9.497733), #45deg71 (90, 1000, 9.523879), #90deg72 (np.array([45,90]),np.array([0,1000]),73 np.array([[9.80616, 9.83207964],74 [9.49773256, 9.5238791]]))75 ])76def test_g(lat,alt,should_be):77 val = atm.g(lat,alt)78 npt.assert_allclose(val, should_be, rtol=1e-7)79@pytest.mark.parametrize('lat,should_be',[80 (0, 9.780356),81 (45, 9.80616), #45deg82 (90, 9.83208), #90deg83 ])84def test_g0(lat,should_be):85 val = atm.g0(lat)86 npt.assert_allclose(val, should_be, rtol=1e-7)87@pytest.mark.parametrize('alt,ref_temp,ref_alt,lapse_rate,should_be',[88 (0,atm.T0_STD,0,atm.L_STD_ATM,atm.T0_STD),89 (0,atm.T0_STD,0,atm.L_STD_ATM,288.15),90 (0,atm.T0_STD,0,atm.L_DRY_AIR,288.15),91 (1000,atm.T0_STD,0,atm.L_DRY_AIR,278.35),92 (1000,atm.T0_STD,0,atm.L_STD_ATM,281.65),93 (1000,atm.T0_STD,100,atm.L_STD_ATM,282.3),94 (1000,atm.T0_STD,1000,atm.L_STD_ATM,288.15),95 ])96def test_temperature(alt,ref_temp,ref_alt,lapse_rate,should_be):97 val = atm.temperature(alt,ref_temp,ref_alt,lapse_rate)98 npt.assert_allclose(val, should_be, rtol=1e-7)99@pytest.mark.parametrize('mol_mass, lapse_rate, lat, should_be',[100 (atm.M_AIR_AVG, atm.L_STD_ATM, 45, -5.255632),101 (atm.M_AIR_AVG, atm.L_STD_ATM, 0, -5.241802),102 (atm.M_AIR_AVG, atm.L_STD_ATM, 90, -5.269523),103 (atm.M_AIR_AVG, atm.L_DRY_AIR, 45, -3.485878),104 ])105def test_beta_exp(mol_mass, lapse_rate, lat, should_be):106 val = atm.beta_exp(mol_mass, lapse_rate,lat)107 npt.assert_allclose(val, should_be, rtol=1e-7)108@pytest.mark.parametrize('alt,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be', [109 (0.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,101325),110 (100.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,100129.493856),111 (1000.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,89875.07181),112 (0.0, 42, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,42),113 (0.0, 42, 273.15, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,42),114 (100.0, 42, 273.15, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,41.477378),115 (0.0, atm.p0, 273.15, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,101325),116 (100.0, atm.p0, 273.15, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,100064.17512),117 (0.0, atm.p0, 273.15, 100.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,102598.657973),118 (0.0, atm.p0, 273.15, 0,atm.L_DRY_AIR,atm.M_AIR_AVG,45.0,101325),119 (100.0, atm.p0, atm.T0_STD, 0.0,atm.L_DRY_AIR,atm.M_AIR_AVG,45.0,100128.81154),120 (0.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,20,45.0,101325),121 (100.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,20,45.0,100497.98743),122 (0.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,0,101325),123 (100.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,0,100132.621128),124 (0.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,90,101325),125 (100.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,90,100126.352659),126 ])127def test_pressure(alt,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be):128 val = atm.pressure(alt,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat)129 npt.assert_allclose(val, should_be, rtol=1e-7)130@pytest.mark.parametrize('alt,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be', [131 (0.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,101325/100),132 (100.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,100129.493856/100),133 (1000.0, atm.p0, atm.T0_STD, 0.0,atm.L_STD_ATM,atm.M_AIR_AVG,45.0,89875.07181/100),134 ])135def test_pressure_hPa(alt,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be):136 val = atm.pressure_hPa(alt,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat)137 npt.assert_allclose(val, should_be, rtol=1e-7)138@pytest.mark.parametrize('p, ref_p, ref_temp, ref_alt, lapse_rate, mol_mass, lat, should_be', [139 (atm.p0, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,0),140 (100000, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,110.889658),141 (50000, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,5574.679741),142 (atm.p0, atm.p0, 42,0,42,42,42,0),143 (50000, 50000, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,0),144 (50000, 80000, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,3792.338559),145 (atm.p0, atm.p0, 273.15,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,0),146 (50000, atm.p0, 273.15,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,5284.482982),147 (50000, atm.p0, 300,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,5803.935181),148 (atm.p0, atm.p0, atm.T0_STD,100,atm.L_STD_ATM,atm.M_AIR_AVG,45,100),149 (atm.p0, atm.p0, atm.T0_STD,0,atm.L_DRY_AIR,atm.M_AIR_AVG,45,0),150 (50000, atm.p0, atm.T0_STD,0,atm.L_DRY_AIR,atm.M_AIR_AVG,45,5392.870582),151 (atm.p0, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,20,45,0),152 (50000, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,20,45,7840.324557),153 (atm.p0, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,0),154 (atm.p0, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,0,0),155 (atm.p0, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,90,0),156 (50000, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,0,5588.419043),157 (50000, atm.p0, atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,90,5560.946563),158 ])159def test_pressure2altitude(p, ref_p, ref_temp, ref_alt, lapse_rate, mol_mass, lat, should_be):160 val = atm.pressure2altitude(p, ref_p, ref_temp, ref_alt, lapse_rate,161 mol_mass, lat)162 npt.assert_allclose(val, should_be, rtol=1e-7)163@pytest.mark.parametrize('alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be', [164 (0,None,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,1225.0033852145957),165 (100,None,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,1213.286799),166 (1000,None,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,1111.65185),167 (10000,None,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,412.733471),168 (0,273.15,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,1292.274301),169 (0,300,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,1176.615751),170 (0,None,50000,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,604.492171),171 (0,None,50000,251.9145816835,5574.679741,atm.L_STD_ATM,atm.M_AIR_AVG,45,1225.0033852145957),172 ])173def test_air_density(alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be):174 val = atm.air_density(alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat)175 npt.assert_allclose(val, should_be, rtol=1e-7)176@pytest.mark.parametrize('alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be', [177 (0,None,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,2.5469602223632817e+25),178 (10000,None,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,8.581329e+24),179 ])180def test_air_number_density(alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be):181 val = atm.air_number_density(alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat)182 npt.assert_allclose(val, should_be, rtol=1e-7)183@pytest.mark.parametrize('lbda_mu,should_be', [184 (0.3, 1.000291554210872),185 (0.2, 1.000324)186 ])187def test_refr_idx_300ppm_co2(lbda_mu,should_be):188 val = atm.refr_idx_300ppm_co2(lbda_mu)189 npt.assert_allclose(val, should_be, rtol=1e-7)190def test_refr_idx():191 val = atm.refr_idx()192 should_be=1.000291554210872193 npt.assert_allclose(val, should_be, rtol=1e-7)194def test__F_N2():195 val = atm._F_N2()196 should_be=1.037522197 npt.assert_allclose(val, should_be, rtol=1e-5)198def test__F_O2():199 val = atm._F_O2()200 should_be=1.129265201 npt.assert_allclose(val, should_be, rtol=1e-5)202def test_F_AIR():203 val = atm.F_AIR()204 should_be=1.056395205 npt.assert_allclose(val, should_be, rtol=1e-5)206@pytest.mark.parametrize('lbda_mu,co2_ppm,should_be', [207 (0.3, 400,5.652217e-26),208 (0.5, 400,6.661139e-27),209 (0.9, 400,6.133698e-28),210 (0.5, 500,6.661859e-27),211 (0.5, 100,6.658979e-27),212 ])213def test_sigma_rayleigh(lbda_mu,co2_ppm,should_be):214 val = atm.sigma_rayleigh(lbda_mu,co2_ppm)215 npt.assert_allclose(val, should_be, rtol=1e-5)216@pytest.mark.parametrize('alt,lbda_mu,co2_ppm,should_be', [217 (0,0.3,400,1.439597e-06),218 (1000,0.3,400,1.306389e-06),219 (10000,0.3,400,4.850354e-07),220 (0,0.5,400,1.696566e-07),221 (0,0.9,400,1.562228e-08),222 (0,0.3,400,1.439597e-06),223 ])224def test_rayleigh_vol_sc_coeff(alt,lbda_mu,co2_ppm,should_be):225 val = atm.rayleigh_vol_sc_coeff(alt,lbda_mu,co2_ppm)226 npt.assert_allclose(val, should_be, rtol=1e-5)227@pytest.mark.filterwarnings('ignore')228@pytest.mark.parametrize('alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be', [229 (0,None,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,1225.0033852145957)230 ])231def test_density(alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be):232 val = atm.density(alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat)233 npt.assert_allclose(val, should_be, rtol=1e-7)234@pytest.mark.filterwarnings('ignore')235@pytest.mark.parametrize('alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be', [236 (0,None,atm.p0,atm.T0_STD,0,atm.L_STD_ATM,atm.M_AIR_AVG,45,2.5469602223632817e+25)237 ])238def test_number_density(alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat,should_be):239 val = atm.number_density(alt,temp,ref_p,ref_temp,ref_alt,lapse_rate,mol_mass,lat)240 npt.assert_allclose(val, should_be, rtol=1e-7)241if __name__ == "__main__":242 import sys...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

1"""2This file contains tests of the Message model.3"""4# django imports5import django.test6# django_messages imports7from django_messages.models import Message8class MessageModelTest( django.test.TestCase ):9 10 #----------------------------------------------------------------------------11 # Constants-ish12 #----------------------------------------------------------------------------13 #----------------------------------------------------------------------------14 # instance methods15 #----------------------------------------------------------------------------16 def setUp( self ):17 18 """19 setup tasks. Call function that we'll re-use.20 """21 # call TestHelper.standardSetUp()22 pass23 #-- END function setUp() --#24 25 def test_create_message( self ):26 27 # declare variables28 me = "test_create_message"29 application = ""30 message = ""31 message_type = None32 label = ""33 status = ""34 tag_list = []35 message_instance = None36 test_application = ""37 test_message = ""38 test_message_type = ""39 test_label = ""40 test_status = ""41 test_tag_list = []42 test_tag_qs = None43 test_tag_count = -144 what_is_it = ""45 test_value = ""46 should_be = -147 do_strict = False48 do_partial = False49 error_string = ""50 test_qs = None51 match_count = -152 message_qs = None53 message_count = -154 55 #----------------------------------------------------------------------#56 # Defaults57 #----------------------------------------------------------------------#58 # set up message values59 message = "test message"60 61 # make instance62 message_instance = Message.create_message( message )63 64 # make sure there are values for everything.65 66 # application67 what_is_it = "application"68 test_application = message_instance.application69 test_value = test_application70 should_be = Message.APPLICATION_DEFAULT71 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""72 self.assertEqual( test_value, should_be, msg = error_string )73 74 # message type75 what_is_it = "message_type"76 test_message_type = message_instance.message_type77 test_value = test_message_type78 should_be = None79 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""80 self.assertEqual( test_value, should_be, msg = error_string )81 82 # message83 what_is_it = "message"84 test_message = message_instance.message85 test_value = test_message86 should_be = message87 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""88 self.assertEqual( test_value, should_be, msg = error_string )89 90 # label91 what_is_it = "label"92 test_label = message_instance.label93 test_value = test_label94 should_be = None95 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""96 self.assertEqual( test_value, should_be, msg = error_string )97 # status98 what_is_it = "status"99 test_status = message_instance.status100 test_value = test_status101 should_be = Message.STATUS_DEFAULT102 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""103 self.assertEqual( test_value, should_be, msg = error_string )104 # should be no tags.105 what_is_it = "tag count"106 test_tag_qs = message_instance.tags.all()107 test_tag_count = test_tag_qs.count()108 test_value = test_tag_count109 should_be = 0110 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""111 self.assertEqual( test_value, should_be, msg = error_string )112 #----------------------------------------------------------------------#113 # Values set114 #----------------------------------------------------------------------#115 # set up message values116 application = "unit_test"117 message = "test message"118 message_type = "test message type"119 label = "test"120 status = Message.STATUS_NEW121 tag_list = [ "awesome", "test" ]122 123 # create instance124 # make instance125 message_instance = Message.create_message( message,126 message_type_IN = message_type,127 application_IN = application,128 label_IN = label,129 tag_list_IN = tag_list,130 status_IN = status )131 132 # make sure there are values for everything.133 134 # application135 what_is_it = "application"136 test_application = message_instance.application137 test_value = test_application138 should_be = application139 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""140 self.assertEqual( test_value, should_be, msg = error_string )141 142 # message143 what_is_it = "message"144 test_message = message_instance.message145 test_value = test_message146 should_be = message147 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""148 self.assertEqual( test_value, should_be, msg = error_string )149 150 # message type151 what_is_it = "message_type"152 test_message_type = message_instance.message_type153 test_value = test_message_type154 should_be = message_type155 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""156 self.assertEqual( test_value, should_be, msg = error_string )157 158 # label159 what_is_it = "label"160 test_label = message_instance.label161 test_value = test_label162 should_be = label163 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""164 self.assertEqual( test_value, should_be, msg = error_string )165 # status166 what_is_it = "status"167 test_status = message_instance.status168 test_value = test_status169 should_be = status170 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""171 self.assertEqual( test_value, should_be, msg = error_string )172 # should be no tags.173 what_is_it = "tag count"174 test_tag_qs = message_instance.tags.all()175 test_tag_count = test_tag_qs.count()176 test_value = test_tag_count177 should_be = 2178 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""179 self.assertEqual( test_value, should_be, msg = error_string )180 181 #----------------------------------------------------------------------#182 # try database lookups.183 #----------------------------------------------------------------------#184 185 # get all messages186 message_qs = Message.objects.all()187 188 # how many?189 what_is_it = "message count"190 message_count = message_qs.count()191 test_value = message_count192 should_be = 2193 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""194 self.assertEqual( test_value, should_be, msg = error_string )195 196 # set up message values197 application = "unit_test"198 message = "test message"199 label = "test"200 status = Message.STATUS_NEW201 tag_list = [ "awesome", "test" ]202 203 # get message for application = "unit_test"204 message_qs = message_qs.filter( application = application )205 message_instance = message_qs.get()206 # application207 what_is_it = "application"208 test_application = message_instance.application209 test_value = test_application210 should_be = application211 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""212 self.assertEqual( test_value, should_be, msg = error_string )213 214 # message215 what_is_it = "message"216 test_message = message_instance.message217 test_value = test_message218 should_be = message219 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""220 self.assertEqual( test_value, should_be, msg = error_string )221 222 # message type223 what_is_it = "message_type"224 test_message_type = message_instance.message_type225 test_value = test_message_type226 should_be = message_type227 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""228 self.assertEqual( test_value, should_be, msg = error_string )229 230 # label231 what_is_it = "label"232 test_label = message_instance.label233 test_value = test_label234 should_be = label235 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""236 self.assertEqual( test_value, should_be, msg = error_string )237 # status238 what_is_it = "status"239 test_status = message_instance.status240 test_value = test_status241 should_be = status242 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""243 self.assertEqual( test_value, should_be, msg = error_string )244 # should be 2 tags.245 what_is_it = "tag count"246 test_tag_qs = message_instance.tags.all()247 test_tag_count = test_tag_qs.count()248 test_value = test_tag_count249 should_be = 2250 error_string = "Found " + what_is_it + " \"" + str( test_value ) + "\", should be \"" + str( should_be ) + "\""251 self.assertEqual( test_value, should_be, msg = error_string )252 #-- END test method test_create_message() --#...

Full Screen

Full Screen

__test__.py

Source:__test__.py Github

copy

Full Screen

1import unittest2import sys3from io import StringIO4from main import interpret5from exceptions import UndefinedError6class InterpreterTest(unittest.TestCase):7 def setUp(self):8 self.env = {}9 def assert_eval(self, insert, should_be):10 result = interpret(insert, self.env)11 self.assertEqual(result, should_be)12 def assert_raise(self, insert, should_be):13 with self.assertRaises(should_be):14 interpret(insert, self.env)15class OperationTest(InterpreterTest):16 def test_op_1(self):17 insert = "(SETQ X 3)"18 should_be = "3"19 self.assert_eval(insert, should_be)20 def test_op_2(self):21 insert = "(+ 6 3)"22 should_be = "9"23 self.assert_eval(insert, should_be)24 def test_op_3(self):25 insert = "(+ 3 (* 5 6))"26 should_be = "33"27 self.assert_eval(insert, should_be)28class BasicFunctionsTest(InterpreterTest):29 def test_basic_1(self):30 insert = "(LIST 'X X 'Y)"31 def test_basic_2(self):32 insert = "(LIST 'X X 'Y)"33 self.assert_raise(insert, UndefinedError)34 def test_basic_3(self):35 insert = "(SETQ X 5)"36 should_be = "5"37 self.assert_eval(insert, should_be)38 insert = "(LIST 'X X 'Y)"39 should_be = "(X 5 Y)"40 self.assert_eval(insert, should_be)41 def test_basic_4(self):42 insert = "(CAR '(X Y Z))"43 should_be = "X"44 self.assert_eval(insert, should_be)45 insert = "(CAR '((X) Y Z))"46 should_be = "(X)"47 self.assert_eval(insert, should_be)48 def test_basic_5(self):49 insert = "(CDR '(X Y Z))"50 should_be = "(Y Z)"51 self.assert_eval(insert, should_be)52 def test_basic_6(self):53 insert = "(SETQ X '(1 2 3))"54 should_be = "(1 2 3)"55 self.assert_eval(insert, should_be)56 insert = "(CAR (CDR (CDR X)))"57 should_be = "3"58 self.assert_eval(insert, should_be)59 insert = "(CADDR X)"60 should_be = "3"61 self.assert_eval(insert, should_be)62 def test_basic_7(self):63 insert = "(CONS 'A '(B C D))"64 should_be = "(A B C D)"65 self.assert_eval(insert, should_be)66 insert = "(CONS '(E) '(1 2 3))"67 should_be = "((E) 1 2 3)"68 self.assert_eval(insert, should_be)69 def test_basic_8(self):70 insert = "(REVERSE '(A B C D))"71 should_be = "(D C B A)"72 self.assert_eval(insert, should_be)73 def test_basic_9(self):74 insert = "(APPEND '(A C) '(B D) '(E F))"75 should_be = "(A C B D E F)"76 self.assert_eval(insert, should_be)77 def test_basic_10(self):78 insert = "(LENGTH '(A B C))"79 should_be = "3"80 self.assert_eval(insert, should_be)81 insert = "(LENGTH '((A B C)))"82 should_be = "1"83 self.assert_eval(insert, should_be)84 def test_basic_11(self):85 insert = "(ASSOC 'TWO '((ONE 1)(TWO 2)(THREE 3)))"86 should_be = "(TWO 2)"87 self.assert_eval(insert, should_be)88 def test_basic_12(self):89 insert = "(SETQ MYLIST '(A B C D E F))"90 should_be = "(A B C D E F)"91 self.assert_eval(insert, should_be)92 insert = "(REMOVE 'D MYLIST)"93 should_be = "(A B C E F)"94 self.assert_eval(insert, should_be)95 insert = "(SETQ MYLIST '(A D B C D E D F))"96 should_be = "(A D B C D E D F)"97 self.assert_eval(insert, should_be)98 insert = "(REMOVE 'D MYLIST)"99 should_be = "(A B C E F)"100 self.assert_eval(insert, should_be)101 def test_basic_13(self):102 insert = "(SUBST 'GOOD 'BAD '(I AM BAD))"103 should_be = "(I AM GOOD)"104 self.assert_eval(insert, should_be)105class PredicateFunctionsTest(InterpreterTest):106 def test_predeciate_1(self):107 insert = '(STRINGP "A")'108 should_be = "T"109 self.assert_eval(insert, should_be)110 def test_predeciate_2(self):111 insert = '(STRINGP "HI THERE")'112 should_be = "T"113 self.assert_eval(insert, should_be)114 def test_predeciate_3(self):115 insert = "(>= 5 2)"116 should_be = "T"117 self.assert_eval(insert, should_be)118 def test_predeciate_4(self):119 insert = "(EQUAL 5 5)"120 should_be = "T"121 self.assert_eval(insert, should_be)122 def test_predeciate_5(self):123 insert = "(MINUSP -2)"124 should_be = "T"125 self.assert_eval(insert, should_be)126 def test_predeciate_6(self):127 insert = "(ZEROP 0)"128 should_be = "T"129 self.assert_eval(insert, should_be)130 def test_predeciate_7(self):131 insert = "(NUMBERP 25)"132 should_be = "T"133 self.assert_eval(insert, should_be)134 def test_predeciate_8(self):135 insert = "(NULL NIL)"136 should_be = "T"137 self.assert_eval(insert, should_be)138 def test_predeciate_9(self):139 insert = "(ATOM 'A)"140 should_be = "T"141 self.assert_eval(insert, should_be)142class ConditionalFunctionsTest(InterpreterTest):143 def test_conditional_1(self):144 insert = "(SETQ X 5)"145 should_be = "5"146 self.assert_eval(insert, should_be)147 insert = "(IF (> X 3) (PRINT X) (+ X 5))"148 should_be = "5"149 self.assert_eval(insert, should_be)150if __name__ == "__main__":...

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