Esempio n. 1
0
class TestDiveAirDiveOutput_woExc(TestDive):
    """Test segments output for air dive 1 without exc."""

    expected_result = [
        " DESCENT: at  30m for   1:30 [RT:  1:30], on Air,  SP:0.0, END:29m",
        "   CONST: at  30m for  28:30 [RT: 30:00], on Air,  SP:0.0, END:29m",
        "  ASCENT: at  15m for   1:30 [RT: 31:30], on Air,  SP:0.0, END:14m",
        "    DECO: at  15m for   0:01 [RT: 31:31], on Air,  SP:0.0, END:14m",
        "  ASCENT: at  12m for   1:00 [RT: 32:31], on Air,  SP:0.0, END:11m",
        "    DECO: at  12m for   0:20 [RT: 32:51], on Air,  SP:0.0, END:11m",
        "  ASCENT: at   9m for   1:00 [RT: 33:51], on Air,  SP:0.0, END:8m",
        "    DECO: at   9m for   2:39 [RT: 36:30], on Air,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 37:30], on Air,  SP:0.0, END:5m",
        "    DECO: at   6m for   4:59 [RT: 42:29], on Air,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 43:29], on Air,  SP:0.0, END:2m",
        "    DECO: at   3m for  12:42 [RT: 56:11], on Air,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 57:11], on Air,  SP:0.0, END:0m", ]


    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg1 = SegmentDive(30, 30 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg1], [self.airtank])
        self.profile1.do_dive_without_exceptions()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx],
                'bad segment n°%s (%s)' % (
                    idx, self.profile1.output_segments[idx]))
Esempio n. 2
0
class TestDiveAirDiveOutput_woExc(TestDive):
    """Test segments output for air dive 1 without exc."""

    expected_result = [
        " DESCENT: at  30m for   1:30 [RT:  1:30], on Air,  SP:0.0, END:29m",
        "   CONST: at  30m for  28:30 [RT: 30:00], on Air,  SP:0.0, END:29m",
        "  ASCENT: at  15m for   1:30 [RT: 31:30], on Air,  SP:0.0, END:14m",
        "    DECO: at  15m for   0:01 [RT: 31:31], on Air,  SP:0.0, END:14m",
        "  ASCENT: at  12m for   1:00 [RT: 32:31], on Air,  SP:0.0, END:11m",
        "    DECO: at  12m for   0:20 [RT: 32:51], on Air,  SP:0.0, END:11m",
        "  ASCENT: at   9m for   1:00 [RT: 33:51], on Air,  SP:0.0, END:8m",
        "    DECO: at   9m for   2:39 [RT: 36:30], on Air,  SP:0.0, END:8m",
        "  ASCENT: at   6m for   1:00 [RT: 37:30], on Air,  SP:0.0, END:5m",
        "    DECO: at   6m for   4:59 [RT: 42:29], on Air,  SP:0.0, END:5m",
        "  ASCENT: at   3m for   1:00 [RT: 43:29], on Air,  SP:0.0, END:2m",
        "    DECO: at   3m for  12:42 [RT: 56:11], on Air,  SP:0.0, END:2m",
        "  ASCENT: at   0m for   1:00 [RT: 57:11], on Air,  SP:0.0, END:0m",
    ]

    def setUp(self):
        """Init of the tests."""
        super().setUp()
        diveseg1 = SegmentDive(30, 30 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg1], [self.airtank])
        self.profile1.do_dive_without_exceptions()

    def test_segments(self):
        """Check all segments."""
        for idx in range(len(self.expected_result)):
            self.assertEqual(
                str(self.profile1.output_segments[idx]),
                self.expected_result[idx], 'bad segment n°%s (%s)' %
                (idx, self.profile1.output_segments[idx]))
Esempio n. 3
0
def main(cli_arguments=None):
    """Main entry point.

    main uses the parameters, tanks and dives given in config file(s)
    and/or command line, calculates the dives and return the output in stdout.

    :param list cli_arguments: list of arguments, like sys.argv
    """
    if sys.version_info < (3, 4):
        raise SystemExit("ERROR: This programm needs python 3.4 or greater")

    if cli_arguments is None:
        cli_arguments = sys.argv

    activate_debug()

    # get the version
    try:
        version_file = open("RELEASE-VERSION", "r")
        try:
            version = version_file.readlines()[0]
            settings.__VERSION__ = version.strip()
        finally:
            version_file.close()
    except IOError:
        settings.__VERSION__ = "unknown"

    dipplanner_arguments = DipplannerCliArguments(cli_arguments)
    dives = dipplanner_arguments.dives

    profiles = []
    current_dive = None
    previous_dive = None
    for dive in dives:
        if previous_dive is None:
            current_dive = Dive(dives[dive]['segments'].values(),
                                dives[dive]['tanks'].values())
        else:
            current_dive = Dive(dives[dive]['segments'].values(),
                                dives[dive]['tanks'].values(), previous_dive)
        if dives[dive]['surface_interval']:
            current_dive.do_surface_interval(dives[dive]['surface_interval'])

        current_dive.do_dive_without_exceptions()
        profiles.append(current_dive)
        previous_dive = current_dive
        # now, dive exceptins do not stop the program anymore, but can be
        # displayed in the output template instead. The used MUST take care of
        # the result.

    # now calculate no flight time based on the last dive
    ######current_dive.no_flight_time_wo_exception()

    # now Prepare the output
    env = Environment(loader=PackageLoader('dipplanner', 'templates'))
    tpl = env.get_template(settings.TEMPLATE)
    # pylint: disable=no-member
    text = tpl.render(settings=settings, dives=profiles)
    # pylint: enable=no-member
    print(text)
Esempio n. 4
0
def main(cli_arguments=None):
    """Main entry point.

    main uses the parameters, tanks and dives given in config file(s)
    and/or command line, calculates the dives and return the output in stdout.

    :param list cli_arguments: list of arguments, like sys.argv
    """
    if sys.version_info < (3, 4):
        raise SystemExit("ERROR: This programm needs python 3.4 or greater")

    if cli_arguments is None:
        cli_arguments = sys.argv

    activate_debug()

    # get the version
    try:
        version_file = open("RELEASE-VERSION", "r")
        try:
            version = version_file.readlines()[0]
            settings.__VERSION__ = version.strip()
        finally:
            version_file.close()
    except IOError:
        settings.__VERSION__ = "unknown"

    dipplanner_arguments = DipplannerCliArguments(cli_arguments)
    dives = dipplanner_arguments.dives

    profiles = []
    current_dive = None
    previous_dive = None
    for dive in dives:
        if previous_dive is None:
            current_dive = Dive(
                dives[dive]['segments'].values(),
                dives[dive]['tanks'].values())
        else:
            current_dive = Dive(
                dives[dive]['segments'].values(),
                dives[dive]['tanks'].values(),
                previous_dive
            )
        if dives[dive]['surface_interval']:
            current_dive.do_surface_interval(dives[dive]['surface_interval'])

        current_dive.do_dive_without_exceptions()
        profiles.append(current_dive)
        previous_dive = current_dive
        # now, dive exceptins do not stop the program anymore, but can be
        # displayed in the output template instead. The used MUST take care of
        # the result.

    # now calculate no flight time based on the last dive
    ######current_dive.no_flight_time_wo_exception()

    # now Prepare the output
    env = Environment(loader=PackageLoader('dipplanner', 'templates'))
    tpl = env.get_template(settings.TEMPLATE)
    # pylint: disable=no-member
    text = tpl.render(settings=settings, dives=profiles)
    # pylint: enable=no-member
    print(text)
Esempio n. 5
0
class TestDiveAirDiveOutput_woExc(TestDive):

    def setUp(self):
        TestDive.setUp(self)
        diveseg1 = SegmentDive(30, 30 * 60, self.airtank, 0)
        self.profile1 = Dive([diveseg1], [self.airtank])
        self.profile1.do_dive_without_exceptions()

    def test_segment1(self):
        self.assertEqual(str(self.profile1.output_segments[0]),
                         ' DESCENT: at  30m for   1:30 [RT:  1:30], '
                         'on Air,  SP:0.0, END:29m',
                         'bad segment (%s)'
                         % self.profile1.output_segments[0])

    def test_segment2(self):
        self.assertEqual(str(self.profile1.output_segments[1]),
                         '   CONST: at  30m for  28:30 [RT: 30:00], '
                         'on Air,  SP:0.0, END:29m',
                         'bad segment (%s)'
                         % self.profile1.output_segments[1])

    def test_segment3(self):
        self.assertEqual(str(self.profile1.output_segments[2]),
                         '  ASCENT: at  15m for   1:30 [RT: 31:30], '
                         'on Air,  SP:0.0, END:14m',
                         'bad segment (%s)'
                         % self.profile1.output_segments[2])

    def test_segment4(self):
        self.assertEqual(str(self.profile1.output_segments[3]),
                         '    DECO: at  15m for   0:01 [RT: 31:31], '
                         'on Air,  SP:0.0, END:14m',
                         'bad segment (%s)'
                         % self.profile1.output_segments[3])

    def test_segment5(self):
        self.assertEqual(str(self.profile1.output_segments[4]),
                         '    DECO: at  12m for   0:25 [RT: 31:56], '
                         'on Air,  SP:0.0, END:11m',
                         'bad segment (%s)'
                         % self.profile1.output_segments[4])

    def test_segment6(self):
        self.assertEqual(str(self.profile1.output_segments[5]),
                         '    DECO: at   9m for   2:42 [RT: 34:38], '
                         'on Air,  SP:0.0, END:8m',
                         'bad segment (%s)'
                         % self.profile1.output_segments[5])

    def test_segment7(self):
        self.assertEqual(str(self.profile1.output_segments[6]),
                         '    DECO: at   6m for   5:02 [RT: 39:40], '
                         'on Air,  SP:0.0, END:5m',
                         'bad segment (%s)'
                         % self.profile1.output_segments[6])

    def test_segment8(self):
        self.assertEqual(str(self.profile1.output_segments[7]),
                         '    DECO: at   3m for   8:44 [RT: 48:24], '
                         'on Air,  SP:0.0, END:2m',
                         'bad segment (%s)'
                         % self.profile1.output_segments[7])