Пример #1
0
    def test_mid_state_start(self):
        """
        Test starting a parser with a state in the middle of processing.
        """
        log.debug('===== START TEST MID-STATE START RECOVERED =====')

        in_file = self.open_file(FILE3)

        # Start at the beginning of record 27 (of 52 total)
        initial_state = {FlortStateKey.POSITION: 2579}

        parser = self.create_rec_parser(in_file, new_state=initial_state)

        # Generate a list of expected result particles.
        expected_particle = []
        for expected in EXPECTED_FILE3[-26:]:
            particle = FlortDjDclRecoveredInstrumentDataParticle(expected)
            expected_particle.append(particle)

        # In a single read, get all particles for this file.
        result = parser.get_records(len(expected_particle))
        self.assertEqual(result, expected_particle)

        self.assertEqual(self.rec_exception_callback_value, None)
        in_file.close()

        log.debug('===== START TEST MID-STATE START TELEMETERED =====')

        in_file = self.open_file(FILE2)

        # Start at the beginning of record 11 (of 30 total).
        initial_state = {FlortStateKey.POSITION: 1017}

        parser = self.create_tel_parser(in_file, new_state=initial_state)

        # Generate a list of expected result particles.
        expected_particle = []
        for expected in EXPECTED_FILE2[-20:]:
            particle = FlortDjDclTelemeteredInstrumentDataParticle(expected)
            expected_particle.append(particle)

        # In a single read, get all particles for this file.
        result = parser.get_records(len(expected_particle))
        self.assertEqual(result, expected_particle)

        self.assertEqual(self.tel_exception_callback_value, None)
        in_file.close()

        log.debug('===== END TEST MID-STATE START =====')
Пример #2
0
    def test_get_many(self):
        """
        Read a file and pull out multiple data particles at one time.
        Verify that the results are those we expected.
        """
        log.debug('===== START TEST GET MANY RECOVERED =====')

        with self.open_file(FILE5) as in_file:
            parser = FlortDjDclParser(self.rec_config, in_file,
                                      self.exception_callback)

            # Generate a list of expected result particles.
            expected_particle = []
            for expected in EXPECTED_FILE5:
                particle = FlortDjDclRecoveredInstrumentDataParticle(expected)
                particle.generate_dict()
                expected_particle.append(particle)

            # In a single read, get all particles for this file.
            result = parser.get_records(len(expected_particle))
            self.assertEqual(result, expected_particle)

            self.assertEqual(self.exception_callback_value, [])

        log.debug('===== START TEST GET MANY TELEMETERED =====')
        with self.open_file(FILE4) as in_file:
            parser = FlortDjDclParser(self.tel_config, in_file,
                                      self.exception_callback)

            # Generate a list of expected result particles.
            expected_particle = []
            for expected in EXPECTED_FILE4:
                particle = FlortDjDclTelemeteredInstrumentDataParticle(
                    expected)
                particle.generate_dict()
                expected_particle.append(particle)

            # In a single read, get all particles for this file.
            result = parser.get_records(len(expected_particle))
            self.assertEqual(result, expected_particle)

            self.assertEqual(self.exception_callback_value, [])

        log.debug('===== END TEST GET MANY =====')
Пример #3
0
    def test_simple(self):
        """
        Read data from a file and pull out data particles
        one at a time. Verify that the results are those we expected.
        """
        log.debug('===== START TEST SIMPLE RECOVERED =====')
        in_file = self.open_file(FILE2)
        parser = self.create_rec_parser(in_file)

        for expected in EXPECTED_FILE2:

            # Generate expected particle
            expected_particle = FlortDjDclRecoveredInstrumentDataParticle(
                expected)

            # Get record and verify.
            result = parser.get_records(1)
            self.assertEqual(result, [expected_particle])

        self.assertEqual(self.rec_exception_callback_value, None)
        in_file.close()

        log.debug('===== START TEST SIMPLE TELEMETERED =====')
        in_file = self.open_file(FILE3)
        parser = self.create_tel_parser(in_file)

        for expected in EXPECTED_FILE3:

            # Generate expected particle
            expected_particle = FlortDjDclTelemeteredInstrumentDataParticle(
                expected)

            # Get record and verify.
            result = parser.get_records(1)
            self.assertEqual(result, [expected_particle])

        self.assertEqual(self.tel_exception_callback_value, None)
        in_file.close()

        log.debug('===== END TEST SIMPLE =====')
Пример #4
0
    def test_get_many(self):
        """
        Read a file and pull out multiple data particles at one time.
        Verify that the results are those we expected.
        """
        log.debug("===== START TEST GET MANY RECOVERED =====")

        with self.open_file(FILE5) as in_file:
            parser = FlortDjDclParser(self.rec_config, in_file, self.exception_callback)

            # Generate a list of expected result particles.
            expected_particle = []
            for expected in EXPECTED_FILE5:
                particle = FlortDjDclRecoveredInstrumentDataParticle(expected)
                particle.generate_dict()
                expected_particle.append(particle)

            # In a single read, get all particles for this file.
            result = parser.get_records(len(expected_particle))
            self.assertEqual(result, expected_particle)

            self.assertEqual(self.exception_callback_value, [])

        log.debug("===== START TEST GET MANY TELEMETERED =====")
        with self.open_file(FILE4) as in_file:
            parser = FlortDjDclParser(self.tel_config, in_file, self.exception_callback)

            # Generate a list of expected result particles.
            expected_particle = []
            for expected in EXPECTED_FILE4:
                particle = FlortDjDclTelemeteredInstrumentDataParticle(expected)
                particle.generate_dict()
                expected_particle.append(particle)

            # In a single read, get all particles for this file.
            result = parser.get_records(len(expected_particle))
            self.assertEqual(result, expected_particle)

            self.assertEqual(self.exception_callback_value, [])

        log.debug("===== END TEST GET MANY =====")
Пример #5
0
    def test_set_state(self):
        """
        This test verifies that the state can be changed after starting.
        Some particles are read and then the parser state is modified to
        skip ahead or back.
        """
        log.debug('===== START TEST SET STATE RECOVERED =====')

        in_file = self.open_file(FILE4)
        parser = self.create_rec_parser(in_file)

        # Read and verify 5 particles (of the 25).
        for expected in EXPECTED_FILE4[:5]:

            # Generate expected particle
            expected_particle = FlortDjDclRecoveredInstrumentDataParticle(
                expected)

            # Get record and verify.
            result = parser.get_records(1)
            self.assertEqual(result, [expected_particle])

        # Skip ahead in the file so that we get the last 10 particles.
        new_state = {FlortStateKey.POSITION: 2118}

        # Set the state.
        parser.set_state(new_state)

        # Read and verify the last 10 particles.
        for expected in EXPECTED_FILE4[-10:]:

            # Generate expected particle
            expected_particle = FlortDjDclRecoveredInstrumentDataParticle(
                expected)

            # Get record and verify.
            result = parser.get_records(1)
            self.assertEqual(result, [expected_particle])

        log.debug('===== START TEST SET STATE TELEMETERED =====')

        in_file = self.open_file(FILE5)
        parser = self.create_tel_parser(in_file)

        # Read and verify 20 particles (of the 24).
        for expected in EXPECTED_FILE5[:20]:

            # Generate expected particle
            expected_particle = FlortDjDclTelemeteredInstrumentDataParticle(
                expected)

            # Get record and verify.
            result = parser.get_records(1)
            self.assertEqual(result, [expected_particle])

        # Skip back in the file so that we get the last 17 particles.
        new_state = {
            FlortStateKey.POSITION: 992,
        }

        # Set the state.
        parser.set_state(new_state)

        # Read and verify the last 17 particles.
        for expected in EXPECTED_FILE5[-17:]:

            # Generate expected particle
            expected_particle = FlortDjDclTelemeteredInstrumentDataParticle(
                expected)

            # Get record and verify.
            result = parser.get_records(1)
            self.assertEqual(result, [expected_particle])

        log.debug('===== END TEST SET STATE =====')
Пример #6
0
 def stream_config(cls):
     return [FlortDjDclRecoveredInstrumentDataParticle.type(), FlortDjDclTelemeteredInstrumentDataParticle.type()]
Пример #7
0
 def stream_config(cls):
     return [
         FlortDjDclRecoveredInstrumentDataParticle.type(),
         FlortDjDclTelemeteredInstrumentDataParticle.type()
     ]