def _generate_fsnode_subjects(self, filenames): """Given filenames, generate a set of subjects for invalidation predicate matching.""" file_paths = ((six.text_type(f), six.text_type(os.path.dirname(f))) for f in filenames) for file_path, parent_dir_path in file_paths: yield Path(file_path) yield Path(parent_dir_path ) # Invalidate the parent dirs DirectoryListing. # TODO: See https://github.com/pantsbuild/pants/issues/3117. yield DescendantAddresses(parent_dir_path)
def test_nodes_symlink_globbed_file(self): self.assert_fsnodes( Files, ['d.ln/b/*.txt'], [ # NB: Needs to stat every path on the way down to track whether # it is traversing a symlink. (Path('d.ln'), Stats), (Link('d.ln'), ReadLink), (Path('a'), Stats), (Path('a/b'), Stats), (Dir('a/b'), DirectoryListing), (Path('a/b/2'), Stats), (Path('a/b/1.txt'), Stats), ])
def generate_subjects(self, filenames): """Given filenames, generate a set of subjects for invalidation predicate matching.""" for f in filenames: # Stats, ReadLink, or FileContent for the literal path. yield Path(f) yield File(f) yield Link(f) # DirectoryListings for parent dirs. yield Dir(dirname(f))
def test_nodes_symlink_file(self): self.assert_fsnodes(Files, ['c.ln/2'], [ (Link('c.ln'), ReadLink), (Path('c.ln'), Stats), (Path('a/b'), Stats), (Path('a/b/2'), Stats), ]) self.assert_fsnodes(Files, ['d.ln/b/1.txt'], [ (Path('d.ln'), Stats), (Link('d.ln'), ReadLink), (Path('a'), Stats), (Path('a/b'), Stats), (Path('a/b/1.txt'), Stats), ])
def test_nodes_symlink_globbed_dir(self): self.assert_fsnodes( Files, ['*/2'], [ # Glob the root. (Dir(''), DirectoryListing), # Stat each entry. (Path('a'), Stats), (Path('c.ln'), Stats), (Path('d.ln'), Stats), (Path('4.txt'), Stats), # Read links to determine whether they're actually directories. (Link('c.ln'), ReadLink), (Link('d.ln'), ReadLink), # Stat the detination of one link (the other was already stat'd during the initial list). (Path('a/b'), Stats), # Look up the literal in each path. (Path('a/b/2'), Stats), (Path('a/2'), Stats), ])
def test_literal(self): subdir = 'foo' name = 'Blah.java' self.assert_files_equals([Path(name)], '', [name]) self.assert_files_equals([Path(join(subdir, name))], subdir, [name]) self.assert_files_equals([PathLiteral(Files, subdir, name)], '', [join(subdir, name)])
def test_nodes_file(self): self.assert_fsnodes(Files, ['4.txt'], [ (Path('4.txt'), Stats), ])
def _generate_fsnode_subjects(self, filenames): """Given filenames, generate a set of subjects for invalidation predicate matching.""" file_paths = ((six.text_type(f), six.text_type(os.path.dirname(f))) for f in filenames) for file_path, parent_dir_path in file_paths: yield Path(file_path) yield Path(parent_dir_path) # Invalidate the parent dirs DirectoryListing.
class StorageTest(unittest.TestCase): TEST_KEY = b'hello' TEST_VALUE = b'world' TEST_PATH = Path('/foo') TEST_PATH2 = Path('/bar') class SomeException(Exception): pass def setUp(self): self.storage = Storage.create(in_memory=True) self.result = StepResult(state='something') self.request = StepRequest(step_id=123, node='some node', dependencies={ 'some dep': 'some state', 'another dep': 'another state' }, project_tree='some project tree') def test_lmdb_key_value_store(self): lmdb = Lmdb.create()[0] with closing(lmdb) as kvs: # Initially key does not exist. self.assertFalse(kvs.get(self.TEST_KEY)) # Now write a key value pair and read back. written = kvs.put(self.TEST_KEY, self.TEST_VALUE) self.assertTrue(written) self.assertEquals(self.TEST_VALUE, kvs.get(self.TEST_KEY).getvalue()) # Write the same key again will not overwrite. self.assertFalse(kvs.put(self.TEST_KEY, self.TEST_VALUE)) def test_storage(self): with closing(self.storage) as storage: key = storage.put(self.TEST_PATH) self.assertEquals(self.TEST_PATH, storage.get(key)) # The deserialized blob is equal by not the same as the input data. self.assertFalse(storage.get(key) is self.TEST_PATH) # Any other keys won't exist in the subjects. self.assertNotEqual(self.TEST_KEY, key) with self.assertRaises(InvalidKeyError): self.assertFalse(storage.get(self.TEST_KEY)) # Verify key and value's types must match. key._type = str with self.assertRaises(ValueError): storage.get(key) def test_storage_key_mappings(self): with closing(self.storage) as storage: key1 = storage.put(self.TEST_PATH) key2 = storage.put(self.TEST_PATH2) storage.add_mapping(key1, key2) self.assertEquals(key2, storage.get_mapping(key1)) # key2 isn't mapped to any other key. self.assertIsNone(storage.get_mapping(key2)) def test_key_for_request(self): with closing(self.storage) as storage: keyed_request = storage.key_for_request(self.request) for dep, dep_state in keyed_request.dependencies.items(): self.assertEquals(Key, type(dep)) self.assertEquals(Key, type(dep_state)) self.assertIs(self.request.node, keyed_request.node) self.assertIs(self.request.project_tree, keyed_request.project_tree) self.assertEquals(keyed_request, storage.key_for_request(keyed_request)) def test_resolve_request(self): with closing(self.storage) as storage: keyed_request = storage.key_for_request(self.request) resolved_request = storage.resolve_request(keyed_request) self.assertEquals(self.request, resolved_request) self.assertIsNot(self.request, resolved_request) self.assertEquals(resolved_request, self.storage.resolve_request(resolved_request)) def test_key_for_result(self): with closing(self.storage) as storage: keyed_result = storage.key_for_result(self.result) self.assertEquals(Key, type(keyed_result.state)) self.assertEquals(keyed_result, storage.key_for_result(keyed_result)) def test_resolve_result(self): with closing(self.storage) as storage: keyed_result = storage.key_for_result(self.result) resolved_result = storage.resolve_result(keyed_result) self.assertEquals(self.result, resolved_result) self.assertIsNot(self.result, resolved_result) self.assertEquals(resolved_result, self.storage.resolve_result(resolved_result))