Beispiel #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 the 21st record (of 42 total).
        initial_state = {DostaStateKey.POSITION: 2738}

        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[-22:]:
            particle = DostaAbcdjmDclRecoveredInstrumentDataParticle(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 the 33rd record (of 44 total).
        initial_state = {DostaStateKey.POSITION: 4079}

        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[-12:]:
            particle = DostaAbcdjmDclTelemeteredInstrumentDataParticle(
                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 =====')
    def test_invalid_metadata_records(self):
        """
        Read data from a file containing invalid metadata records as well
        as valid metadata records and sensor data records.
        Verify that the sensor data records can be read correctly
        and that invalid metadata records are detected.
        File 5 has 3 invalid metadata records.
        File 6 has 6 invalid metadata records.
        """
        log.debug('===== START TEST INVALID METADATA RECOVERED =====')
        in_file = self.open_file(FILE5)
        parser = self.create_rec_parser(in_file)

        for expected in EXPECTED_FILE5:

            # Generate expected particle
            expected_particle = DostaAbcdjmDclRecoveredInstrumentDataParticle(
                expected)

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

        self.assertEqual(len(self.exception_callback_value), 3)
        in_file.close()

        self.exception_callback_value = []  # reset exceptions

        log.debug('===== START TEST INVALID METADATA TELEMETERED =====')
        in_file = self.open_file(FILE6)
        parser = self.create_tel_parser(in_file)

        # Generate a list of expected result particles.
        expected_particle = []
        for expected in EXPECTED_FILE6:
            particle = DostaAbcdjmDclTelemeteredInstrumentDataParticle(
                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(len(self.exception_callback_value), 6)
        in_file.close()

        log.debug('===== END TEST INVALID METADATA =====')
Beispiel #3
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 =====')
        in_file = self.open_file(FILE3)
        parser = self.create_rec_parser(in_file)

        # Generate a list of expected result particles.
        expected_particle = []
        for expected in EXPECTED_FILE3:
            particle = DostaAbcdjmDclRecoveredInstrumentDataParticle(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 GET MANY TELEMETERED =====')
        in_file = self.open_file(FILE3)
        parser = self.create_tel_parser(in_file)

        # Generate a list of expected result particles.
        expected_particle = []
        for expected in EXPECTED_FILE3:
            particle = DostaAbcdjmDclTelemeteredInstrumentDataParticle(
                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 GET MANY =====')
Beispiel #4
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(FILE1)
        parser = self.create_rec_parser(in_file)

        for expected in EXPECTED_FILE1:

            # Generate expected particle
            expected_particle = DostaAbcdjmDclRecoveredInstrumentDataParticle(
                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(FILE1)
        parser = self.create_tel_parser(in_file)

        for expected in EXPECTED_FILE1:

            # Generate expected particle
            expected_particle = DostaAbcdjmDclTelemeteredInstrumentDataParticle(
                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 =====')
Beispiel #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(FILE2)
        parser = self.create_rec_parser(in_file)

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

            # Generate expected particle
            expected_particle = DostaAbcdjmDclRecoveredInstrumentDataParticle(
                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 = {DostaStateKey.POSITION: 4301}

        # Set the state.
        parser.set_state(new_state)

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

            # Generate expected particle
            expected_particle = DostaAbcdjmDclRecoveredInstrumentDataParticle(
                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(FILE3)
        parser = self.create_tel_parser(in_file)

        # Read and verify 30 particles (of the 42).
        for expected in EXPECTED_FILE3[:30]:

            # Generate expected particle
            expected_particle = DostaAbcdjmDclTelemeteredInstrumentDataParticle(
                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 25 particles.
        new_state = {
            DostaStateKey.POSITION: 2414,
        }

        # Set the state.
        parser.set_state(new_state)

        # Read and verify the last 25 particles.
        for expected in EXPECTED_FILE3[-25:]:

            # Generate expected particle
            expected_particle = DostaAbcdjmDclTelemeteredInstrumentDataParticle(
                expected)

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

        log.debug('===== END TEST SET STATE =====')
Beispiel #6
0
 def stream_config(cls):
     return [
         DostaAbcdjmDclRecoveredInstrumentDataParticle.type(),
         DostaAbcdjmDclTelemeteredInstrumentDataParticle.type()
     ]
Beispiel #7
0
 def stream_config(cls):
     return [
         DostaAbcdjmDclRecoveredInstrumentDataParticle.type(),
         DostaAbcdjmDclTelemeteredInstrumentDataParticle.type()
     ]