Beispiel #1
0
    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)
Beispiel #2
0
 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)
Beispiel #3
0
  def test_get_processed_files(self):
    """
    Checks that get_processed_files() provides the expected results after
    iterating over our test data.
    """

    desc_path = os.path.join(DESCRIPTOR_TEST_DATA, 'example_descriptor')
    last_modified = int(os.stat(desc_path).st_mtime)

    reader = stem.descriptor.reader.DescriptorReader(desc_path)

    with reader:
      list(reader)  # iterates over all of the descriptors

    self.assertEqual({desc_path: last_modified}, reader.get_processed_files())
Beispiel #4
0
 def test_get_processed_files(self):
   """
   Checks that get_processed_files() provides the expected results after
   iterating over our test data.
   """
   
   expected_results = {}
   
   for root, _, files in os.walk(DESCRIPTOR_TEST_DATA):
     for filename in files:
       path = os.path.join(root, filename)
       last_modified = int(os.stat(path).st_mtime)
       expected_results[path] = last_modified
   
   reader = stem.descriptor.reader.DescriptorReader(DESCRIPTOR_TEST_DATA)
   with reader: list(reader) # iterates over all of the descriptors
   
   self.assertEquals(expected_results, reader.get_processed_files())
Beispiel #5
0
    def test_get_processed_files(self):
        """
    Checks that get_processed_files() provides the expected results after
    iterating over our test data.
    """

        expected_results = {}

        for root, _, files in os.walk(DESCRIPTOR_TEST_DATA):
            for filename in files:
                path = os.path.join(root, filename)
                last_modified = int(os.stat(path).st_mtime)
                expected_results[path] = last_modified

        reader = stem.descriptor.reader.DescriptorReader(DESCRIPTOR_TEST_DATA)

        with reader:
            list(reader)  # iterates over all of the descriptors

        self.assertEqual(expected_results, reader.get_processed_files())