How to use load_data_file method in gabbi

Best Python code snippet using gabbi_python

test_override_function.py

Source:test_override_function.py Github

copy

Full Screen

2import unittest3import numpy as np4from scipy.io import loadmat5from airline_alloc.override_functions import *6def load_data_file(file_name):7 #../../../MATLAB/Data/<data_file>8 file_path = os.path.join(9 os.path.dirname(__file__),10 os.path.pardir,11 os.path.pardir,12 os.path.pardir,13 'MATLAB',14 'Data',15 file_name)16 17 return loadmat(file_path, squeeze_me=True, struct_as_record=False)18 19class RangeExtractTestCase(unittest.TestCase):20 def test_3routes(self):21 mat_file = load_data_file('inputs_before_3routes.mat')22 mat_file = mat_file['Inputs']23 24 comp = RangeExtract()25 comp.RVector = mat_file.RVector26 comp.distance = np.array([2000, 1500, 1000])27 28 comp.execute()29 print comp.ind30 31 self.assertTrue(np.allclose(comp.ind, np.array([80, 1782, 674]) - 1))32 33 def test_11routes(self):34 mat_file = load_data_file('inputs_before_11routes.mat')35 mat_file = mat_file['Inputs']36 37 comp = RangeExtract()38 comp.RVector = mat_file.RVector39 comp.distance = np.array([40 162,753,974,1094,41 1357,1455,2169,2249,42 2269,2337,2350])43 comp.execute()44 self.assertTrue(np.allclose(comp.ind, np.array([45 394,1598,410,2042,46 615,742,427,1501,47 1308,414,1317]) - 1))48 49 def test_31routes(self):50 mat_file = load_data_file('inputs_before_31routes.mat')51 mat_file = mat_file['Inputs']52 53 comp = RangeExtract()54 comp.RVector = mat_file.RVector55 comp.distance = np.array([56 113,174,289,303,57 324,331,342,375,58 407,427,484,486,59 531,543,550,570,60 594,609,622,680,61 747,758,760,823,62 837,991,1098,1231,63 1407,1570,1626])64 comp.execute()65 self.assertTrue(np.allclose(comp.ind, np.array([66 1483,1045,1944,1856,67 754,1463,1718,948,68 416,1801,1795,225,69 845,919,840,1746,70 1739,1797,1947,1987,71 1429,1802,2060,1897,72 1410,1241,971,1399,73 1597,2028,1433]) - 1))74 75class InitializationTestCase(unittest.TestCase):76 77 def test_init_3routes(self):78 inputs = load_data_file('inputs_before_3routes.mat')79 inputs = inputs['Inputs']80 81 constants = load_data_file('constants_before_3routes.mat')82 constants = constants['Constants']83 84 comp = Initialization()85 comp.ac_ind = np.array([9, 10]) - 186 comp.distance = np.array([2000, 1500, 1000])87 comp.DVector = np.array([[1,2,3],[300, 700, 200]]).T88 comp.ACNum = np.array([6,4])89 comp.RVector_in = inputs.RVector90 comp.AvailPax_in = inputs.AvailPax91 comp.route_ind = np.array([80,1782,674]) - 192 comp.MH_in = constants.MH93 94 comp.execute()95 96 inputs = load_data_file('inputs_after_3routes.mat')97 inputs = inputs['Inputs']98 99 constants = load_data_file('constants_after_3routes.mat')100 constants = constants['Constants']101 102 self.assertTrue(np.allclose(comp.RVector_out, inputs.RVector))103 self.assertTrue(np.allclose(comp.AvailPax_out, inputs.AvailPax))104 self.assertTrue(np.allclose(comp.TurnAround, inputs.TurnAround))105 self.assertTrue(np.allclose(comp.J, 3))106 self.assertTrue(np.allclose(comp.K, 2))107 self.assertTrue(np.allclose(comp.Lim, inputs.Lim))108 109 def test_init_11routes(self):110 inputs = load_data_file('inputs_before_3routes.mat')111 inputs = inputs['Inputs']112 113 constants = load_data_file('constants_before_3routes.mat')114 constants = constants['Constants']115 116 comp = Initialization()117 comp.ac_ind = np.array([9, 10]) - 1118 comp.distance = np.array([119 162,753,974,1094,120 1357,1455,2169,2249,121 2269,2337,2350])122 comp.DVector = np.array([123 np.arange(1,12),[124 41,1009,89,661,125 1041,358,146,97,126 447,194,263]]).T127 comp.ACNum = np.array([12,8])128 comp.RVector_in = inputs.RVector129 comp.AvailPax_in = inputs.AvailPax130 comp.route_ind = np.array([131 394,1598,410,2042,132 615,742,427,1501,133 1308,414,1317]) - 1134 comp.MH_in = constants.MH135 136 print repr(comp.DVector)137 comp.execute()138 139 inputs = load_data_file('inputs_after_11routes.mat')140 inputs = inputs['Inputs']141 142 constants = load_data_file('constants_after_11routes.mat')143 constants = constants['Constants']144 145 self.assertTrue(np.allclose(comp.RVector_out, inputs.RVector))146 self.assertTrue(np.allclose(comp.AvailPax_out, inputs.AvailPax))147 self.assertTrue(np.allclose(comp.TurnAround, inputs.TurnAround))148 self.assertTrue(np.allclose(comp.J, 11))149 self.assertTrue(np.allclose(comp.K, 2))150 self.assertTrue(np.allclose(comp.Lim, inputs.Lim))151 152 def test_init_31routes(self):153 inputs = load_data_file('inputs_before_31routes.mat')154 inputs = inputs['Inputs']155 156 constants = load_data_file('constants_before_31routes.mat')157 constants = constants['Constants']158 159 comp = Initialization()160 comp.ac_ind = np.array([6,10,4,9,3,8]) - 1161 comp.distance = np.array([162 113,174,289,303,163 324,331,342,375,164 407,427,484,486,165 531,543,550,570,166 594,609,622,680,167 747,758,760,823,168 837,991,1098,1231,169 1407,1570,1626])170 comp.DVector = np.array([171 np.arange(1,32),[172 99,80,51,184,173 263,169,158,135,174 284,184,92,132,175 754,150,238,264,176 365,749,234,50,177 101,124,175,221,178 258,105,112,129,179 506,134,266]]).T180 comp.ACNum = np.array([1,7,2,8,19,1])181 comp.RVector_in = inputs.RVector182 comp.AvailPax_in = inputs.AvailPax183 comp.route_ind = np.array([184 1483,1045,1944,1856,185 754,1463,1718,948,186 416,1801,1795,225,187 845,919,840,1746,188 1739,1797,1947,1987,189 1429,1802,2060,1897,190 1410,1241,971,1399,191 1597,2028,1433]) - 1192 193 comp.MH_in = constants.MH194 195 comp.execute()196 197 inputs = load_data_file('inputs_after_31routes.mat')198 inputs = inputs['Inputs']199 200 constants = load_data_file('constants_after_31routes.mat')201 constants = constants['Constants']202 203 self.assertTrue(np.allclose(comp.RVector_out, inputs.RVector))204 self.assertTrue(np.allclose(comp.AvailPax_out, inputs.AvailPax))205 self.assertTrue(np.allclose(comp.TurnAround, inputs.TurnAround))206 self.assertTrue(np.allclose(comp.J, 31))207 self.assertTrue(np.allclose(comp.K, 6))208 self.assertTrue(np.allclose(comp.Lim, inputs.Lim))209 210class ArrayFilterTestCase(unittest.TestCase):211 def test_3routes(self):212 outputs_before = load_data_file('outputs_before_3routes.mat')213 outputs_before = outputs_before['Outputs']214 215 coefficients_before = load_data_file('coefficients_before_3routes.mat')216 coefficients_before = coefficients_before['Coefficients'] 217 218 outputs_after = load_data_file('outputs_after_3routes.mat')219 outputs_after = outputs_after['Outputs']220 221 coefficients_after = load_data_file('coefficients_after_3routes.mat')222 coefficients_after = coefficients_after['Coefficients'] 223 224 comp = ArrayFilter()225 comp.route_ind = np.array([80,1782,674]) - 1226 comp.ac_ind = np.array([9,10]) - 1227 228 #TicketPrice229 comp.original = outputs_before.TicketPrice230 comp.execute()231 232 print comp.filtered233 print outputs_after.TicketPrice234 self.assertTrue(np.allclose(comp.filtered, outputs_after.TicketPrice))235 236 #Fuelburn237 comp.original = coefficients_before.Fuelburn238 comp.execute()239 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Fuelburn))240 241 #Doc242 comp.original = coefficients_before.Doc243 comp.execute()244 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Doc))245 246 #Nox247 comp.original = coefficients_before.Nox248 comp.execute()249 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Nox))250 251 #BlockTime252 comp.original = coefficients_before.BlockTime253 comp.execute()254 self.assertTrue(np.allclose(comp.filtered, coefficients_after.BlockTime))255 256 def test_11routes(self):257 outputs_before = load_data_file('outputs_before_11routes.mat')258 outputs_before = outputs_before['Outputs']259 260 coefficients_before = load_data_file('coefficients_before_11routes.mat')261 coefficients_before = coefficients_before['Coefficients'] 262 263 outputs_after = load_data_file('outputs_after_11routes.mat')264 outputs_after = outputs_after['Outputs']265 266 coefficients_after = load_data_file('coefficients_after_11routes.mat')267 coefficients_after = coefficients_after['Coefficients'] 268 269 comp = ArrayFilter()270 comp.route_ind = np.array([271 394,1598,410,2042,272 615,742,427,1501,273 1308,414,1317]) - 1274 comp.ac_ind = np.array([9,10]) - 1275 276 #TicketPrice277 comp.original = outputs_before.TicketPrice278 comp.execute()279 self.assertTrue(np.allclose(comp.filtered, outputs_after.TicketPrice))280 281 #Fuelburn282 comp.original = coefficients_before.Fuelburn283 comp.execute()284 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Fuelburn))285 286 #Doc287 comp.original = coefficients_before.Doc288 comp.execute()289 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Doc))290 291 #Nox292 comp.original = coefficients_before.Nox293 comp.execute()294 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Nox))295 296 #BlockTime297 comp.original = coefficients_before.BlockTime298 comp.execute()299 self.assertTrue(np.allclose(comp.filtered, coefficients_after.BlockTime))300 301 def test_31routes(self):302 outputs_before = load_data_file('outputs_before_31routes.mat')303 outputs_before = outputs_before['Outputs']304 305 coefficients_before = load_data_file('coefficients_before_31routes.mat')306 coefficients_before = coefficients_before['Coefficients'] 307 308 outputs_after = load_data_file('outputs_after_31routes.mat')309 outputs_after = outputs_after['Outputs']310 311 coefficients_after = load_data_file('coefficients_after_31routes.mat')312 coefficients_after = coefficients_after['Coefficients'] 313 314 comp = ArrayFilter()315 comp.route_ind = np.array([316 1483,1045,1944,1856,317 754,1463,1718,948,318 416,1801,1795,225,319 845,919,840,1746,320 1739,1797,1947,1987,321 1429,1802,2060,1897,322 1410,1241,971,1399,323 1597,2028,1433]) - 1324 comp.ac_ind = np.array([6,10,4,9,3,8]) - 1325 326 #TicketPrice327 comp.original = outputs_before.TicketPrice328 comp.execute()329 self.assertTrue(np.allclose(comp.filtered, outputs_after.TicketPrice))330 331 #Fuelburn332 comp.original = coefficients_before.Fuelburn333 comp.execute()334 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Fuelburn))335 336 #Doc337 comp.original = coefficients_before.Doc338 comp.execute()339 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Doc))340 341 #Nox342 comp.original = coefficients_before.Nox343 comp.execute()344 self.assertTrue(np.allclose(comp.filtered, coefficients_after.Nox))345 346 #BlockTime347 comp.original = coefficients_before.BlockTime348 comp.execute()349 self.assertTrue(np.allclose(comp.filtered, coefficients_after.BlockTime))350 351class MaxTripTestCase(unittest.TestCase):352 353 def test_3routes(self):354 inputs_after = load_data_file('inputs_after_3routes.mat')355 inputs_after = inputs_after['Inputs']356 357 coefficients_after = load_data_file('coefficients_after_3routes.mat')358 coefficients_after = coefficients_after['Coefficients']359 360 constants_after = load_data_file('constants_after_3routes.mat')361 constants_after = constants_after['Constants']362 363 comp = MaxTrip_3Routes()364 comp.J = 3365 comp.K = 2366 comp.ACNum = inputs_after.ACNum367 comp.BlockTime = coefficients_after.BlockTime368 comp.MH = constants_after.MH369 comp.TurnAround = inputs_after.TurnAround370 371 comp.execute()372 373 self.assertTrue(np.allclose(comp.MaxTrip, inputs_after.MaxTrip))374 375 def test_11routes(self):376 inputs_after = load_data_file('inputs_after_11routes.mat')377 inputs_after = inputs_after['Inputs']378 379 coefficients_after = load_data_file('coefficients_after_11routes.mat')380 coefficients_after = coefficients_after['Coefficients']381 382 constants_after = load_data_file('constants_after_11routes.mat')383 constants_after = constants_after['Constants']384 385 comp = MaxTrip_11Routes()386 comp.J = 11387 comp.K = 2388 comp.ACNum = inputs_after.ACNum389 comp.BlockTime = coefficients_after.BlockTime390 comp.MH = constants_after.MH391 comp.TurnAround = inputs_after.TurnAround392 393 comp.execute()394 395 print comp.MaxTrip396 print inputs_after.MaxTrip397 398 self.assertTrue(np.allclose(comp.MaxTrip, inputs_after.MaxTrip))399 400 def test_31routes(self):401 inputs_after = load_data_file('inputs_after_31routes.mat')402 inputs_after = inputs_after['Inputs']403 404 coefficients_after = load_data_file('coefficients_after_31routes.mat')405 coefficients_after = coefficients_after['Coefficients']406 407 constants_after = load_data_file('constants_after_31routes.mat')408 constants_after = constants_after['Constants']409 410 comp = MaxTrip_31Routes()411 comp.J = 31412 comp.K = 6413 comp.ACNum = inputs_after.ACNum414 comp.BlockTime = coefficients_after.BlockTime415 comp.MH = constants_after.MH416 comp.TurnAround = inputs_after.TurnAround417 418 comp.execute()419 420 self.assertTrue(np.allclose(comp.MaxTrip, inputs_after.MaxTrip))421 ...

Full Screen

Full Screen

test_JobBrowserBFF_validation.py

Source:test_JobBrowserBFF_validation.py Github

copy

Full Screen

...4import unittest5import os6import json7class ValidationTests(TestBase):8 def load_data_file(self, method_name, outcome_type, data_type, file_name):9 data_path = os.path.join(os.path.dirname(__file__), '..', '..', 'data',10 'methods', method_name, outcome_type, data_type, file_name)11 with open(data_path) as fin:12 return json.load(fin)13 def get_data_files(self, method_name, outcome_type, data_type):14 dir_path = os.path.join(os.path.dirname(__file__), '..', '..', 'data',15 'methods', method_name, outcome_type, data_type)16 dirs = []17 for file_name in os.listdir(dir_path):18 dirs.append(file_name)19 return dirs20 # Uncomment to skip this test21 @unittest.skip("skipped test_query_jobs_validate_params_happy")22 def test_query_jobs_validate_params_happy(self):23 try:24 validation = Validation(load_schemas=True)25 method_names = [26 'query_jobs', 'get_jobs', 'get_job_log',27 'cancel_job'28 ]29 for method_name in method_names:30 sample_files = self.get_data_files(method_name, 'happy', 'params')31 for sample_file in sample_files:32 data = self.load_data_file(method_name, 'happy', 'params', sample_file)33 validation.validate_params(method_name, data)34 except Exception as ex:35 self.assert_no_exception(ex)36 return37 # Uncomment to skip this test38 # @unittest.skip("skipped test_get_jobs_validate_result_happy")39 def test_get_jobs_validate_result_happy(self):40 try:41 validation = Validation(load_schemas=True)42 method_names = [43 'get_jobs', 'query_jobs', 'get_job_log',44 'cancel_job', 'get_client_groups',45 'get_job_states', 'get_job_types', 'get_log_levels',46 'get_searchable_job_fields'47 ]48 for method_name in method_names:49 sample_files = self.get_data_files(method_name, 'happy', 'result')50 for sample_file in sample_files:51 data = self.load_data_file(method_name, 'happy', 'result', sample_file)52 validation.validate_result(method_name, data)53 except Exception as ex:54 self.assert_no_exception(ex)...

Full Screen

Full Screen

test_sensor_data_file.py

Source:test_sensor_data_file.py Github

copy

Full Screen

...6from mat.header import Header7from mat.sensor_data_file import NoDataError8class TestSensorDataFile(TestCase):9 def test_create_lid(self):10 data_file = load_data_file(reference_file('test.lid'))11 assert isinstance(data_file, LidDataFile)12 def test_create_bad_file(self):13 with self.assertRaises(WrongFileTypeError):14 load_data_file(reference_file('test.xyz'))15 def test_n_pages_lid(self):16 data_file = load_data_file(reference_file('test.lid'))17 assert data_file.n_pages() == 118 def test_load_page_twice(self):19 data_file = load_data_file(reference_file('test.lid'))20 data_file.page(0)21 data_file.page(0)22 def test_load_calibration_twice(self):23 data_file = load_data_file(reference_file('test.lid'))24 cal = data_file.calibration()25 cal = data_file.calibration()26 assert type(cal) == V3Calibration27 def test_load_header(self):28 data_file = load_data_file(reference_file('test.lid'))29 header = data_file.header()30 header = data_file.header()31 header.parse_header()32 assert type(header) == Header33 def test_seconds_per_page_partial_page(self):34 data_file = load_data_file(reference_file('test.lid'))35 data_file.seconds_per_page()36 def test_read_nonexistent_page(self):37 data_file = load_data_file(reference_file('test.lid'))38 with self.assertRaises(ValueError):39 data_file.page(3)40 def test_mhs_wrong_place(self):41 with self.assertRaises(ValueError):42 load_data_file(reference_file('mhs_wrong_place.lid'))43 def test_no_data_in_lid_file(self):44 with self.assertRaises(NoDataError):...

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