def test_duplicate_names(self) -> None: with self.assertRaises(DuplicateNameError): AddressFamily.create( "name/space", [ AddressMap("name/space/0", {"one": Thing(name="one", age=42)}), AddressMap("name/space/1", {"one": Thing(name="one", age=37)}), ], )
def test_address_family_duplicate_names() -> None: with pytest.raises(DuplicateNameError): AddressFamily.create( "name/space", [ AddressMap( "name/space/0", {"one": TargetAdaptor(type_alias="thing", name="one", age=42)} ), AddressMap( "name/space/1", {"one": TargetAdaptor(type_alias="thing", name="one", age=37)} ), ], )
async def parse_address_family( parser: Parser, build_file_options: BuildFileOptions, prelude_symbols: BuildFilePreludeSymbols, directory: AddressFamilyDir, ) -> AddressFamily: """Given an AddressMapper and a directory, return an AddressFamily. The AddressFamily may be empty, but it will not be None. """ digest_contents = await Get( DigestContents, PathGlobs(globs=( *(os.path.join(directory.path, p) for p in build_file_options.patterns), *(f"!{p}" for p in build_file_options.ignores), )), ) if not digest_contents: raise ResolveError( f"Directory '{directory.path}' does not contain any BUILD files.") address_maps = [ AddressMap.parse(fc.path, fc.content.decode(), parser, prelude_symbols) for fc in digest_contents ] return AddressFamily.create(directory.path, address_maps)
async def parse_address_family(address_mapper: AddressMapper, prelude_symbols: BuildFilePreludeSymbols, directory: Dir) -> AddressFamily: """Given an AddressMapper and a directory, return an AddressFamily. The AddressFamily may be empty, but it will not be None. """ path_globs = PathGlobs(globs=( *(os.path.join(directory.path, p) for p in address_mapper.build_patterns), *(f"!{p}" for p in address_mapper.build_ignore_patterns), )) snapshot = await Get[Snapshot](PathGlobs, path_globs) files_content = await Get[FilesContent](Digest, snapshot.digest) if not files_content: raise ResolveError( 'Directory "{}" does not contain any BUILD files.'.format( directory.path)) address_maps = [] for filecontent_product in files_content: address_maps.append( AddressMap.parse( filecontent_product.path, filecontent_product.content, address_mapper.parser, prelude_symbols, )) return AddressFamily.create(directory.path, address_maps)
def parse_address_map(build_file: str) -> AddressMap: path = "/dev/null" parser = Parser(target_type_aliases=["thing"], object_aliases=BuildFileAliases()) address_map = AddressMap.parse(path, build_file, parser, BuildFilePreludeSymbols(FrozenDict())) assert path == address_map.path return address_map
def test_create_multiple(self) -> None: address_family = AddressFamily.create( "name/space", [ AddressMap("name/space/0", {"one": Thing(name="one", age=42)}), AddressMap("name/space/1", {"two": Thing(name="two", age=37)}), ], ) self.assertEqual("name/space", address_family.namespace) self.assertEqual( { Address.parse("name/space:one"): Thing(name="one", age=42), Address.parse("name/space:two"): Thing(name="two", age=37), }, address_family.addressables, )
def test_address_family_create_multiple() -> None: address_family = AddressFamily.create( "name/space", [ AddressMap( "name/space/0", {"one": TargetAdaptor(type_alias="thing", name="one", age=42)} ), AddressMap( "name/space/1", {"two": TargetAdaptor(type_alias="thing", name="two", age=37)} ), ], ) assert "name/space" == address_family.namespace assert { Address.parse("name/space:one"): TargetAdaptor(type_alias="thing", name="one", age=42), Address.parse("name/space:two"): TargetAdaptor(type_alias="thing", name="two", age=37), } == dict(address_family.addresses_to_target_adaptors.items())
def test_address_family_create_single() -> None: address_family = AddressFamily.create( "", [ AddressMap( "0", { "one": TargetAdaptor(type_alias="thing", name="one", age=42), "two": TargetAdaptor(type_alias="thing", name="two", age=37), }, ) ], ) assert "" == address_family.namespace assert { Address.parse("//:one"): TargetAdaptor(type_alias="thing", name="one", age=42), Address.parse("//:two"): TargetAdaptor(type_alias="thing", name="two", age=37), } == dict(address_family.addresses_to_target_adaptors.items())
def test_create_single(self) -> None: address_family = AddressFamily.create( "", [ AddressMap( "0", { "one": Thing(name="one", age=42), "two": Thing(name="two", age=37) }) ], ) self.assertEqual("", address_family.namespace) self.assertEqual( { Address.parse("//:one"): Thing(name="one", age=42), Address.parse("//:two"): Thing(name="two", age=37), }, address_family.addressables, )
def test_address_family_mismatching_paths() -> None: with pytest.raises(DifferingFamiliesError): AddressFamily.create("one", [ AddressMap("/dev/null/one/0", {}), AddressMap("/dev/null/two/0", {}) ])
def parse_address_map(self, json): path = "/dev/null" address_map = AddressMap.parse(path, json, self._parser, BuildFilePreludeSymbols(FrozenDict())) self.assertEqual(path, address_map.path) yield address_map
def test_mismatching_paths(self) -> None: with self.assertRaises(DifferingFamiliesError): AddressFamily.create("one", [ AddressMap("/dev/null/one/0", {}), AddressMap("/dev/null/two/0", {}) ])