def test_skip_listener_already_read(self): """ Checks that calling set_processed_files() prior to reading makes us skip those files. This also doubles for testing that skip listeners are notified of files that we've already read. """ # path that we want the DescriptorReader to skip test_path = os.path.join(DESCRIPTOR_TEST_DATA, 'example_descriptor') initial_processed_files = {test_path: sys.maxsize} skip_listener = SkipListener() reader = stem.descriptor.reader.DescriptorReader(test_path) reader.register_skip_listener(skip_listener.listener) reader.set_processed_files(initial_processed_files) self.assertEqual(initial_processed_files, reader.get_processed_files()) with reader: list(reader) # iterates over all of the descriptors self.assertEqual(1, len(skip_listener.results)) skipped_path, skip_exception = skip_listener.results[0] self.assertEqual(test_path, skipped_path) self.assertTrue( isinstance(skip_exception, stem.descriptor.reader.AlreadyRead)) self.assertEqual(sys.maxsize, skip_exception.last_modified_when_read)
def test_skip_listener_already_read(self): """ Checks that calling set_processed_files() prior to reading makes us skip those files. This also doubles for testing that skip listeners are notified of files that we've already read. """ # path that we want the DescriptorReader to skip test_path = os.path.join(DESCRIPTOR_TEST_DATA, "example_descriptor") initial_processed_files = {test_path: sys.maxint} skip_listener = SkipListener() reader = stem.descriptor.reader.DescriptorReader(test_path) reader.register_skip_listener(skip_listener.listener) reader.set_processed_files(initial_processed_files) self.assertEquals(initial_processed_files, reader.get_processed_files()) with reader: list(reader) # iterates over all of the descriptors self.assertEquals(1, len(skip_listener.results)) skipped_path, skip_exception = skip_listener.results[0] self.assertEqual(test_path, skipped_path) self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.AlreadyRead)) self.assertEqual(sys.maxint, skip_exception.last_modified_when_read)
def test_multiple_runs(self): """ Runs a DescriptorReader instance multiple times over the same content, making sure that it can be used repeatedly. """ descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, 'example_descriptor') reader = stem.descriptor.reader.DescriptorReader(descriptor_path) with reader: self.assertEqual(1, len(list(reader))) # run it a second time, this shouldn't provide any descriptors because we # have already read it with reader: self.assertEqual(0, len(list(reader))) # clear the DescriptorReader's memory of seeing the file and run it again reader.set_processed_files([]) with reader: self.assertEqual(1, len(list(reader)))
def test_multiple_runs(self): """ Runs a DescriptorReader instance multiple times over the same content, making sure that it can be used repeatedly. """ descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "example_descriptor") reader = stem.descriptor.reader.DescriptorReader(descriptor_path) with reader: self.assertEquals(1, len(list(reader))) # run it a second time, this shouldn't provide any descriptors because we # have already read it with reader: self.assertEquals(0, len(list(reader))) # clear the DescriptorReader's memory of seeing the file and run it again reader.set_processed_files([]) with reader: self.assertEquals(1, len(list(reader)))