Esempio n. 1
0
    def test_empty_lines_okay(self):

        # Create a file
        temp_dir = tempfile.TemporaryDirectory()
        temp_dir_name = temp_dir.name
        test_file = temp_dir_name + '/test.txt'
        logging.info('creating temporary file "%s"', test_file)
        create_file(test_file, SAMPLE_SPACE_DATA)

        # Create a reader to read it at 0.5 second intervals
        reader = TextFileReader(test_file, interval=0.5, tail=True)
        timeout_reader = TimeoutReader(reader,
                                       timeout=1,
                                       empty_is_okay=True,
                                       message='Space Timeout')

        # Our reader should do fine until it gets to the very end after 4 seconds
        start_time = time.time()
        record = timeout_reader.read()
        end_time = time.time()
        self.assertEqual(record, 'Space Timeout')
        self.assertAlmostEqual(end_time - start_time, 3.5, delta=0.3)

        logging.info('Got timeout record "%s" after %g seconds', record,
                     end_time - start_time)
Esempio n. 2
0
    def test_basic(self):

        # Create a file
        temp_dir = tempfile.TemporaryDirectory()
        temp_dir_name = temp_dir.name
        test_file = temp_dir_name + '/test.txt'
        logging.info('creating temporary file "%s"', test_file)
        create_file(test_file, SAMPLE_DATA)

        # Create a reader to read it at 0.5 second intervals
        reader = TextFileReader(test_file, interval=0.5, tail=True)

        timeout_reader = TimeoutReader(reader, timeout=1, message='Timeout')

        # Our reader should do fine until it runs out of records after 2 seconds
        start_time = time.time()
        record = timeout_reader.read()
        end_time = time.time()
        self.assertEqual(record, 'Timeout')
        self.assertAlmostEqual(end_time - start_time, 2.5, delta=0.3)

        logging.info('Got timeout record "%s" after %g seconds', record,
                     end_time - start_time)