def runTest(self): try: altitude_to_pressure(15000) except ValueError: pass else: self.fail('altitude high than 10000m should raise ValueError')
def runTest(self): try: altitude_to_pressure(-10) except ValueError: pass else: self.fail('Negative pressure should raise ValueError')
def test_altitude(self): cli_args = ["dipplanner", "-t", "airtank;0.21;0.0;12;200;50b", "-s", "30;25*60;airtank;0.0", "--altitude=2456", ] _ = DipplannerCliArguments(cli_args) self.assertEqual(settings.AMBIANT_PRESSURE_SURFACE, altitude_to_pressure(2456), "Wrong altitude pressure: %s" % settings.AMBIANT_PRESSURE_SURFACE)
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(6000), 0.471809934056, 10, 'Wrong pressure at 6000m : %s' % altitude_to_pressure(6000))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(100), 1.00129437467, 10, 'Wrong pressure at 100m : %s' % altitude_to_pressure(100))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(6000), 0.471809934056, 10, 'Wrong pressure at 6000m : %s' % altitude_to_pressure(6000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(4000), 0.616402064441, 10, 'Wrong pressure at 4000m : %s' % altitude_to_pressure(4000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(2000), 0.794951974353, 10, 'Wrong pressure at 2000m : %s' % altitude_to_pressure(2000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(1000), 0.898745604274, 10, 'Wrong pressure at 1000m : %s' % altitude_to_pressure(1000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(100), 1.00129437467, 10, 'Wrong pressure at 100m : %s' % altitude_to_pressure(100))
def check_arguments(self, args): """Parse all command lines options. could also exit from program because of wrong arguments """ parsed_config_files = DipplannerConfigFiles(args.config_files) dives = parsed_config_files.dives if dives is None: dives = OrderedDict() if args.gflow: try: settings.GF_LOW = float( safe_eval_calculator(args.gflow.strip('%'))) / 100 except ValueError: self.parser.error("Error while parsing option gflow : %s" % args.gflow) if args.gfhigh: try: settings.GF_HIGH = float( safe_eval_calculator(args.gfhigh.strip('%'))) / 100 except ValueError: self.parser.error("Error while parsing option gfhigh: %s" % args.gfhigh) if args.water: if args.water.lower() == "sea": settings.WATER_DENSITY = settings.SEA_WATER_DENSITY if args.water.lower() == "fresh": settings.WATER_DENSITY = settings.FRESH_WATER_DENSITY if args.altitude: settings.AMBIANT_PRESSURE_SURFACE = altitude_to_pressure( args.altitude) if args.diveconsrate: try: settings.DIVE_CONSUMPTION_RATE = float( safe_eval_calculator(args.diveconsrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "diveconsrate : %s" % args.diveconsrate) if args.decoconsrate: try: settings.DECO_CONSUMPTION_RATE = float( safe_eval_calculator(args.decoconsrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "decoconsrate : %s" % args.decoconsrate) if args.descentrate: try: settings.DESCENT_RATE = float( safe_eval_calculator(args.descentrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "descentrate : %s" % args.descentrate) if args.ascentrate: try: settings.ASCENT_RATE = float( safe_eval_calculator(args.ascentrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "ascentrate : %s" % args.ascentrate) if args.deco_ascentrate: try: settings.DECO_ASCENT_RATE = float( safe_eval_calculator(args.deco_ascentrate)) / 60 except ValueError: self.parser.error( "Error while parsing option " "deco_ascentrate : %s" % args.deco_ascentrate) if args.model: settings.DECO_MODEL = args.model if args.maxppo2: settings.DEFAULT_MAX_PPO2 = args.maxppo2 if args.minppo2: settings.DEFAULT_MIN_PPO2 = args.minppo2 if args.maxend: settings.DEFAULT_MAX_END = args.maxend if args.samegasfordeco: settings.USE_OC_DECO = False if args.forcesegmenttime: settings.RUN_TIME = False if args.depthcalcmethod in ('simple', 'complex'): settings.METHOD_FOR_DEPTH_CALCULATION = args.depthcalcmethod if args.travelswitch in ('late', 'early'): settings.TRAVEL_SWITCH = args.travelswitch if args.surfacetemp is not None: settings.SURFACE_TEMP = args.surfacetemp if args.ambiantpressureatsea: settings.AMBIANT_PRESSURE_SEA_LEVEL = args.ambiantpressureatsea if args.multilevel: settings.MULTILEVEL_MODE = True if args.automatictankrefill: settings.AUTOMATIC_TANK_REFILL = True if args.notankrefill: settings.AUTOMATIC_TANK_REFILL = False # try to find tank(s) and segment(s). # if found, add this dive to the (eventually) other dives defined # in config files. # this will be the last dive tanks = {} if args.tanks: for tank in args.tanks: (name, f_o2, f_he, volume, pressure, rule) = tank.split(";") tanks[name] = Tank( float(f_o2), float(f_he), max_ppo2=settings.DEFAULT_MAX_PPO2, tank_vol=float(safe_eval_calculator(volume)), tank_pressure=float(safe_eval_calculator(pressure)), tank_rule=rule) if tanks == {}: # no tank provided, try to get the previous tanks try: tanks = dives[list(dives.items())[-1][0]]['tanks'] except (KeyError, IndexError): self.parser.error("Error : no tank provided for this dive !") segments = OrderedDict() if args.segments: num_seg = 1 for seg in args.segments: (depth, time, tankname, setpoint) = seg.split(";") # looks for tank in tanks try: # seg_name = 'segment%s' % num_seg # print(seg_name) segments['segment%s' % num_seg] = SegmentDive( float(safe_eval_calculator(depth)), float(safe_eval_calculator(time)), tanks[tankname], float(setpoint)) except KeyError: self.parser.error( "Error : tank name (%s) in not found in tank list !" % tankname) num_seg += 1 segments = OrderedDict(sorted(segments.items(), key=lambda t: t[0])) if args.surfaceinterval: dives['diveCLI'] = {'tanks': tanks, 'segments': segments, 'surface_interval': safe_eval_calculator(args.surfaceinterval)} else: dives['diveCLI'] = {'tanks': tanks, 'segments': segments, 'surface_interval': 0} if args.template: settings.TEMPLATE = args.template # returns self.args = args self.dives = dives
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(4000), 0.616402064441, 10, 'Wrong pressure at 4000m : %s' % altitude_to_pressure(4000))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(5000), 0.540198800085, 10, 'Wrong pressure at 5000m : %s' % altitude_to_pressure(5000))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(3000), 0.701085204119, 10, 'Wrong pressure at 3000m : %s' % altitude_to_pressure(3000))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(2000), 0.794951974353, 10, 'Wrong pressure at 2000m : %s' % altitude_to_pressure(2000))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(1500), 0.845559905236, 10, 'Wrong pressure at 1500m : %s' % altitude_to_pressure(1500))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(1000), 0.898745604274, 10, 'Wrong pressure at 1000m : %s' % altitude_to_pressure(1000))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(500), 0.954608340287, 10, 'Wrong pressure at 500m : %s' % altitude_to_pressure(500))
def check_configs_general_section(self): """Check configs and change default settings values.""" config = self.config if config.has_section('general'): section = 'general' if config.has_option(section, 'deco_model'): model = ''.join(config.get(section, 'deco_model')).strip() if model in ("ZHL16a", "ZHL16b", "ZHL16c"): settings.DECO_MODEL = model if config.has_option(section, 'gf_low'): settings.GF_LOW = float( safe_eval_calculator(''.join(config.get( section, 'gf_low')).strip('%'))) / 100 if config.has_option(section, 'gf_high'): settings.GF_HIGH = float( safe_eval_calculator(''.join(config.get( section, 'gf_high')).strip('%'))) / 100 if config.has_option(section, 'water'): if config.get(section, 'water') == 'sea': settings.WATER_DENSITY = settings.SEA_WATER_DENSITY elif config.get(section, 'water') == 'fresh': settings.WATER_DENSITY = settings.FRESH_WATER_DENSITY if config.has_option(section, 'altitude'): settings.AMBIANT_PRESSURE_SURFACE = altitude_to_pressure( float(config.get(section, 'altitude'))) if config.has_option(section, 'dive_consumption_rate'): settings.DIVE_CONSUMPTION_RATE = float( config.get(section, 'dive_consumption_rate')) / 60 if config.has_option(section, 'deco_consumption_rate'): settings.DECO_CONSUMPTION_RATE = float( config.get(section, 'deco_consumption_rate')) / 60 if config.has_option(section, 'descent_rate'): settings.DESCENT_RATE = float( config.get(section, 'descent_rate')) / 60 if config.has_option(section, 'ascent_rate'): settings.ASCENT_RATE = float( config.get(section, 'ascent_rate')) / 60 if config.has_option(section, 'deco_ascent_rate'): settings.DECO_ASCENT_RATE = float( config.get(section, 'deco_ascent_rate')) / 60 if config.has_option(section, 'max_ppo2'): settings.DEFAULT_MAX_PPO2 = float(config.get(section, 'max_ppo2')) if config.has_option(section, 'min_ppo2'): settings.DEFAULT_MIN_PPO2 = float(config.get(section, 'min_ppo2')) if config.has_option(section, 'max_end'): settings.DEFAULT_MAX_END = float(config.get(section, 'max_end')) if config.has_option(section, 'run_time'): settings.RUN_TIME = config.getboolean(section, 'run_time') if config.has_option(section, 'use_oc_deco'): settings.USE_OC_DECO = config.getboolean(section, 'use_oc_deco') if config.has_option(section, 'multilevel_mode'): settings.MULTILEVEL_MODE = config.getboolean(section, 'multilevel_mode') if config.has_option(section, 'automatic_tank_refill'): settings.AUTOMATIC_TANK_REFILL = config.getboolean( section, 'automatic_tank_refill')
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(7000), 0.4106070795, 10, 'Wrong pressure at 7000m : %s' % altitude_to_pressure(7000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(0), 1.01325, 5, 'Wrong pressure at 0m : %s' % altitude_to_pressure(0))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(8000), 0.355997759308, 10, 'Wrong pressure at 8000m : %s' % altitude_to_pressure(8000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(500), 0.954608340287, 10, 'Wrong pressure at 500m : %s' % altitude_to_pressure(500))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(9000), 0.307424233586, 10, 'Wrong pressure at 9000m : %s' % altitude_to_pressure(9000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(1500), 0.845559905236, 10, 'Wrong pressure at 1500m : %s' % altitude_to_pressure(1500))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(10000), 0.264362335127, 10, 'Wrong pressure at 10000m : %s' % altitude_to_pressure(10000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(3000), 0.701085204119, 10, 'Wrong pressure at 3000m : %s' % altitude_to_pressure(3000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(8000), 0.355997759308, 10, 'Wrong pressure at 8000m : %s' % altitude_to_pressure(8000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(5000), 0.540198800085, 10, 'Wrong pressure at 5000m : %s' % altitude_to_pressure(5000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(10000), 0.264362335127, 10, 'Wrong pressure at 10000m : %s' % altitude_to_pressure(10000))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(7000), 0.4106070795, 10, 'Wrong pressure at 7000m : %s' % altitude_to_pressure(7000))
def runTest(self): self.assertAlmostEqual( altitude_to_pressure(0), 1.01325, 5, 'Wrong pressure at 0m : %s' % altitude_to_pressure(0))
def runTest(self): self.assertAlmostEqual(altitude_to_pressure(9000), 0.307424233586, 10, 'Wrong pressure at 9000m : %s' % altitude_to_pressure(9000))
def check_configs_general_section(self): """Check configs and change default settings values.""" config = self.config if config.has_section('general'): section = 'general' if config.has_option(section, 'deco_model'): model = ''.join(config.get(section, 'deco_model')).strip() if model in ("ZHL16a", "ZHL16b", "ZHL16c"): settings.DECO_MODEL = model if config.has_option(section, 'gf_low'): settings.GF_LOW = float( safe_eval_calculator(''.join(config.get( section, 'gf_low')).strip('%'))) / 100 if config.has_option(section, 'gf_high'): settings.GF_HIGH = float( safe_eval_calculator(''.join(config.get( section, 'gf_high')).strip('%'))) / 100 if config.has_option(section, 'water'): if config.get(section, 'water') == 'sea': settings.WATER_DENSITY = settings.SEA_WATER_DENSITY elif config.get(section, 'water') == 'fresh': settings.WATER_DENSITY = settings.FRESH_WATER_DENSITY if config.has_option(section, 'altitude'): settings.AMBIANT_PRESSURE_SURFACE = altitude_to_pressure( float(config.get(section, 'altitude'))) if config.has_option(section, 'dive_consumption_rate'): settings.DIVE_CONSUMPTION_RATE = float( config.get(section, 'dive_consumption_rate')) / 60 if config.has_option(section, 'deco_consumption_rate'): settings.DECO_CONSUMPTION_RATE = float( config.get(section, 'deco_consumption_rate')) / 60 if config.has_option(section, 'descent_rate'): settings.DESCENT_RATE = float( config.get(section, 'descent_rate')) / 60 if config.has_option(section, 'ascent_rate'): settings.ASCENT_RATE = float(config.get( section, 'ascent_rate')) / 60 if config.has_option(section, 'deco_ascent_rate'): settings.DECO_ASCENT_RATE = float( config.get(section, 'deco_ascent_rate')) / 60 if config.has_option(section, 'max_ppo2'): settings.DEFAULT_MAX_PPO2 = float( config.get(section, 'max_ppo2')) if config.has_option(section, 'min_ppo2'): settings.DEFAULT_MIN_PPO2 = float( config.get(section, 'min_ppo2')) if config.has_option(section, 'max_end'): settings.DEFAULT_MAX_END = float(config.get( section, 'max_end')) if config.has_option(section, 'run_time'): settings.RUN_TIME = config.getboolean(section, 'run_time') if config.has_option(section, 'use_oc_deco'): settings.USE_OC_DECO = config.getboolean( section, 'use_oc_deco') if config.has_option(section, 'multilevel_mode'): settings.MULTILEVEL_MODE = config.getboolean( section, 'multilevel_mode') if config.has_option(section, 'automatic_tank_refill'): settings.AUTOMATIC_TANK_REFILL = config.getboolean( section, 'automatic_tank_refill')
def test_altitude(self): self.assertEqual(settings.AMBIANT_PRESSURE_SURFACE, altitude_to_pressure(1234), "Wrong altitude pressure: %s" % settings.AMBIANT_PRESSURE_SURFACE)
def check_arguments(self, args): """Parse all command lines options. could also exit from program because of wrong arguments """ parsed_config_files = DipplannerConfigFiles(args.config_files) dives = parsed_config_files.dives if dives is None: dives = OrderedDict() if args.gflow: try: settings.GF_LOW = float( safe_eval_calculator(args.gflow.strip('%'))) / 100 except ValueError: self.parser.error("Error while parsing option gflow : %s" % args.gflow) if args.gfhigh: try: settings.GF_HIGH = float( safe_eval_calculator(args.gfhigh.strip('%'))) / 100 except ValueError: self.parser.error("Error while parsing option gfhigh: %s" % args.gfhigh) if args.water: if args.water.lower() == "sea": settings.WATER_DENSITY = settings.SEA_WATER_DENSITY if args.water.lower() == "fresh": settings.WATER_DENSITY = settings.FRESH_WATER_DENSITY if args.altitude: settings.AMBIANT_PRESSURE_SURFACE = altitude_to_pressure( args.altitude) if args.diveconsrate: try: settings.DIVE_CONSUMPTION_RATE = float( safe_eval_calculator(args.diveconsrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "diveconsrate : %s" % args.diveconsrate) if args.decoconsrate: try: settings.DECO_CONSUMPTION_RATE = float( safe_eval_calculator(args.decoconsrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "decoconsrate : %s" % args.decoconsrate) if args.descentrate: try: settings.DESCENT_RATE = float( safe_eval_calculator(args.descentrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "descentrate : %s" % args.descentrate) if args.ascentrate: try: settings.ASCENT_RATE = float( safe_eval_calculator(args.ascentrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "ascentrate : %s" % args.ascentrate) if args.deco_ascentrate: try: settings.DECO_ASCENT_RATE = float( safe_eval_calculator(args.deco_ascentrate)) / 60 except ValueError: self.parser.error("Error while parsing option " "deco_ascentrate : %s" % args.deco_ascentrate) if args.model: settings.DECO_MODEL = args.model if args.maxppo2: settings.DEFAULT_MAX_PPO2 = args.maxppo2 if args.minppo2: settings.DEFAULT_MIN_PPO2 = args.minppo2 if args.maxend: settings.DEFAULT_MAX_END = args.maxend if args.samegasfordeco: settings.USE_OC_DECO = False if args.forcesegmenttime: settings.RUN_TIME = False if args.depthcalcmethod in ('simple', 'complex'): settings.METHOD_FOR_DEPTH_CALCULATION = args.depthcalcmethod if args.travelswitch in ('late', 'early'): settings.TRAVEL_SWITCH = args.travelswitch if args.surfacetemp is not None: settings.SURFACE_TEMP = args.surfacetemp if args.ambiantpressureatsea: settings.AMBIANT_PRESSURE_SEA_LEVEL = args.ambiantpressureatsea if args.multilevel: settings.MULTILEVEL_MODE = True if args.automatictankrefill: settings.AUTOMATIC_TANK_REFILL = True if args.notankrefill: settings.AUTOMATIC_TANK_REFILL = False # try to find tank(s) and segment(s). # if found, add this dive to the (eventually) other dives defined # in config files. # this will be the last dive tanks = {} if args.tanks: for tank in args.tanks: (name, f_o2, f_he, volume, pressure, rule) = tank.split(";") tanks[name] = Tank( float(f_o2), float(f_he), max_ppo2=settings.DEFAULT_MAX_PPO2, tank_vol=float(safe_eval_calculator(volume)), tank_pressure=float(safe_eval_calculator(pressure)), tank_rule=rule) if tanks == {}: # no tank provided, try to get the previous tanks try: tanks = dives[list(dives.items())[-1][0]]['tanks'] except (KeyError, IndexError): self.parser.error("Error : no tank provided for this dive !") segments = OrderedDict() if args.segments: num_seg = 1 for seg in args.segments: (depth, time, tankname, setpoint) = seg.split(";") # looks for tank in tanks try: # seg_name = 'segment%s' % num_seg # print(seg_name) segments['segment%s' % num_seg] = SegmentDive( float(safe_eval_calculator(depth)), float(safe_eval_calculator(time)), tanks[tankname], float(setpoint)) except KeyError: self.parser.error( "Error : tank name (%s) in not found in tank list !" % tankname) num_seg += 1 segments = OrderedDict(sorted(segments.items(), key=lambda t: t[0])) if args.surfaceinterval: dives['diveCLI'] = { 'tanks': tanks, 'segments': segments, 'surface_interval': safe_eval_calculator(args.surfaceinterval) } else: dives['diveCLI'] = { 'tanks': tanks, 'segments': segments, 'surface_interval': 0 } if args.template: settings.TEMPLATE = args.template # returns self.args = args self.dives = dives