Пример #1
0
    def test_happy_path(self):
        """
        Read files and verify that all expected particles can be read.
        Verify that the contents of the particles are correct.
        There should be no exceptions generated.
        """
        log.debug('===== START TEST HAPPY PATH =====')

        with open(os.path.join(RESOURCE_PATH, 'happy_path.txt'),
                  'r') as file_handle:

            NUM_PARTICLES_TO_REQUEST = NUM_EXPECTED_PARTICLES = 10

            parser = Pco2wAbcParser(self._parser_config, file_handle,
                                    self.exception_callback, None, None)

            particles = parser.get_records(NUM_PARTICLES_TO_REQUEST)

            self.assertEquals(len(particles), NUM_EXPECTED_PARTICLES)

            self.assert_particles(particles, "happy_path.yml", RESOURCE_PATH)

            self.assertEqual(self._exception_occurred, False)

        log.debug('===== END TEST HAPPY PATH =====')
Пример #2
0
    def test_invalid_metadata_timestamp(self):
        """
        The file used in this test has error in the timestamp for the first metadata record.
        This results in 9 particles being retrieved instead of 10, and also result in the exception
        callback being called.
        """
        log.debug('===== START TEST INVALID METADATA TIMESTAMP =====')

        with open(
                os.path.join(RESOURCE_PATH, 'invalid_metadata_timestamp.txt'),
                'r') as file_handle:

            NUM_PARTICLES_TO_REQUEST = 10
            NUM_EXPECTED_PARTICLES = 9

            parser = Pco2wAbcParser(self._parser_config, file_handle,
                                    self.exception_callback, None, None)

            particles = parser.get_records(NUM_PARTICLES_TO_REQUEST)

            self.assertEquals(len(particles), NUM_EXPECTED_PARTICLES)

            self.assert_particles(particles, "invalid_metadata_timestamp.yml",
                                  RESOURCE_PATH)

            self.assertEqual(self._exception_occurred, True)

        log.debug('===== END TEST INVALID METADATA TIMESTAMP =====')
Пример #3
0
    def test_power_record_missing_timestamp(self):
        """
        The file used in this test has a power record with a missing timestamp.
        This results in 9 particles being retrieved instead of 10, and also result in the exception
        callback being called.
        """
        log.debug('===== START TEST POWER RECORD MISSING TIMESTAMP =====')

        with open(
                os.path.join(RESOURCE_PATH,
                             'power_record_missing_timestamp.txt'),
                'r') as file_handle:

            NUM_PARTICLES_TO_REQUEST = 10
            NUM_EXPECTED_PARTICLES = 9

            parser = Pco2wAbcParser(self._parser_config, file_handle,
                                    self.exception_callback, None, None)

            particles = parser.get_records(NUM_PARTICLES_TO_REQUEST)

            self.assertEquals(len(particles), NUM_EXPECTED_PARTICLES)

            self.assert_particles(particles,
                                  "power_record_missing_timestamp.yml",
                                  RESOURCE_PATH)

            self.assertEqual(self._exception_occurred, True)

        log.debug('===== END TEST POWER RECORD MISSING TIMESTAMP =====')
Пример #4
0
    def test_real_file(self):
        """
        Verify that the correct number of particles are generated
        from a real file.
        """
        log.debug('===== START TEST REAL FILE =====')

        with open(os.path.join(RESOURCE_PATH, 'SAMI_C0069_300614.txt'),
                  'r') as file_handle:

            NUM_PARTICLES_TO_REQUEST = 2500
            NUM_EXPECTED_PARTICLES = 2063

            parser = Pco2wAbcParser(self._parser_config, file_handle,
                                    self.exception_callback, None, None)

            particles = parser.get_records(NUM_PARTICLES_TO_REQUEST)

            log.info(len(particles))

            self.assertEquals(len(particles), NUM_EXPECTED_PARTICLES)

            self.assertEqual(self._exception_occurred, False)

        log.debug('===== END TEST REAL FILE =====')
Пример #5
0
    def test_no_particles(self):
        """
        Verify that no particles are produced if the input file
        has no instrument records.
        """
        log.debug('===== START TEST NO PARTICLES =====')

        with open(os.path.join(RESOURCE_PATH, 'no_particles.txt'), 'r') as file_handle:

            NUM_PARTICLES_TO_REQUEST = 10
            NUM_EXPECTED_PARTICLES = 0

            parser = Pco2wAbcParser(self._parser_config,
                                    file_handle,
                                    self.exception_callback,
                                    None,
                                    None)

            particles = parser.get_records(NUM_PARTICLES_TO_REQUEST)

            self.assertEquals(len(particles), NUM_EXPECTED_PARTICLES)

            self.assertEqual(self._exception_occurred, False)

        log.debug('===== END TEST NO PARTICLES =====')
Пример #6
0
    def test_invalid_record_type(self):
        """
        The file used in this test has a record type that does not match any of the expected record types.
        This results in 9 particles being retrieved instead of 10, and also result in the exception
        callback being called.
        """
        log.debug('===== START TEST INVALID RECORD TYPE =====')

        with open(os.path.join(RESOURCE_PATH, 'invalid_record_type.txt'),
                  'r') as file_handle:

            NUM_PARTICLES_TO_REQUEST = 10
            NUM_EXPECTED_PARTICLES = 9

            parser = Pco2wAbcParser(self._parser_config, file_handle,
                                    self.exception_callback, None, None)

            particles = parser.get_records(NUM_PARTICLES_TO_REQUEST)

            self.assertEquals(len(particles), NUM_EXPECTED_PARTICLES)

            self.assert_particles(particles, "invalid_record_type.yml",
                                  RESOURCE_PATH)

            self.assertEqual(self._exception_occurred, True)

        log.debug('===== END TEST INVALID RECORD TYPE =====')
Пример #7
0
    def _create_empty_instrument_blank_dict():
        """
        Overrides method in Pco2wAbcParser.
        """

        instrument_dict = Pco2wAbcParser._create_empty_instrument_blank_dict()

        # Load the dictionary entries for this subclass
        dcl_dict = Pco2wAbcDclParser._create_dcl_extension_dict()

        # Update the dict from base class with the dictionary entries that are unique
        # to this subclass
        instrument_dict.update(dcl_dict)

        return instrument_dict
Пример #8
0
    def _create_empty_instrument_blank_dict():
        """
        Overrides method in Pco2wAbcParser.
        """

        instrument_dict = Pco2wAbcParser._create_empty_instrument_blank_dict()

        # Load the dictionary entries for this subclass
        dcl_dict = Pco2wAbcDclParser._create_dcl_extension_dict()

        # Update the dict from base class with the dictionary entries that are unique
        # to this subclass
        instrument_dict.update(dcl_dict)

        return instrument_dict
Пример #9
0
    def _create_empty_metadata_dict():
        """
        Overrides method in Pco2wAbcParser.
        """

        # Load the dictionary from the base class
        metadata_dict = Pco2wAbcParser._create_empty_metadata_dict()

        # Load the DCL dictionary entries for this subclass
        dcl_dict = Pco2wAbcDclParser._create_dcl_extension_dict()

        # Update the dict from base class with the dictionary entries that are unique
        # to this subclass
        metadata_dict.update(dcl_dict)

        return metadata_dict
Пример #10
0
    def _create_empty_metadata_dict():
        """
        Overrides method in Pco2wAbcParser.
        """

        # Load the dictionary from the base class
        metadata_dict = Pco2wAbcParser._create_empty_metadata_dict()

        # Load the DCL dictionary entries for this subclass
        dcl_dict = Pco2wAbcDclParser._create_dcl_extension_dict()

        # Update the dict from base class with the dictionary entries that are unique
        # to this subclass
        metadata_dict.update(dcl_dict)

        return metadata_dict
Пример #11
0
    def process(self):
        log = get_logger()

        with open(self._sourceFilePath, "r") as file_handle:

            def exception_callback(exception):
                log.debug("Exception: %s", exception)
                self._particleDataHdlrObj.setParticleDataCaptureFailure()

            parser = Pco2wAbcParser(self._parser_config, file_handle,
                                    exception_callback, None, None)

            driver = DataSetDriver(parser, self._particleDataHdlrObj)

            driver.processFileStream()

        return self._particleDataHdlrObj