예제 #1
0
    def test_full_graph_for_planner_example(self):
        address_mapper = AddressMapper(
            JsonParser(TARGET_TABLE),
            prelude_glob_patterns=(),
            build_patterns="*.BUILD.json",
        )
        rules = create_graph_rules(address_mapper) + create_fs_rules()

        fullgraph_str = self.create_full_graph(rules)

        print("---diagnostic------")
        print(fullgraph_str)
        print("/---diagnostic------")

        in_root_rules = False
        in_all_rules = False
        all_rules = []
        root_rule_lines = []
        for line in fullgraph_str.splitlines():
            if line.startswith("  // root subject types:"):
                pass
            elif line.startswith("  // root entries"):
                in_root_rules = True
            elif line.startswith("  // internal entries"):
                in_all_rules = True
            elif in_all_rules:
                all_rules.append(line)
            elif in_root_rules:
                root_rule_lines.append(line)
            else:
                pass

        self.assertTrue(6 < len(all_rules))
        self.assertTrue(12 < len(root_rule_lines))  # 2 lines per entry
예제 #2
0
 def test_empty(self) -> None:
     """Test that parsing an empty BUILD file results in an empty AddressFamily."""
     address_mapper = AddressMapper(
         parser=JsonParser(TEST_TABLE),
         prelude_glob_patterns=(),
         build_file_imports_behavior=BuildFileImportsBehavior.error,
     )
     af = run_rule(
         parse_address_family,
         rule_args=[
             address_mapper,
             BuildFilePreludeSymbols(FrozenDict()),
             Dir("/dev/null")
         ],
         mock_gets=[
             MockGet(
                 product_type=Snapshot,
                 subject_type=PathGlobs,
                 mock=lambda _: Snapshot(Digest("abc", 10),
                                         ("/dev/null/BUILD", ), ()),
             ),
             MockGet(
                 product_type=FilesContent,
                 subject_type=Digest,
                 mock=lambda _: FilesContent(
                     [FileContent(path="/dev/null/BUILD", content=b"")]),
             ),
         ],
     )
     self.assertEqual(len(af.objects_by_name), 0)
예제 #3
0
    def setUp(self) -> None:
        # Set up a scheduler that supports address mapping.
        address_mapper = AddressMapper(
            parser=JsonParser(TARGET_TABLE),
            prelude_glob_patterns=(),
            build_file_imports_behavior=BuildFileImportsBehavior.error,
            build_patterns=("*.BUILD.json", ),
        )

        # We add the `unhydrated_structs` rule because it is otherwise not used in the core engine.
        rules = [unhydrated_structs
                 ] + create_fs_rules() + create_graph_rules(address_mapper)

        project_tree = self.mk_fs_tree(
            os.path.join(os.path.dirname(__file__), "examples/mapper_test"))
        self.build_root = project_tree.build_root
        self.scheduler = self.mk_scheduler(rules=rules,
                                           project_tree=project_tree)

        self.a_b = Address.parse("a/b")
        self.a_b_target = Target(
            address=self.a_b,
            dependencies=["//a/d/e"],
            configurations=["//a/d/e", Struct(embedded="yes")],
            type_alias="target",
        )
예제 #4
0
class AddressMapTest(unittest.TestCase):
    _parser = JsonParser(SymbolTable({"thing": Thing}))

    @contextmanager
    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_parse(self) -> None:
        with self.parse_address_map(
                dedent("""
                {
                  "type_alias": "thing",
                  "name": "one",
                  "age": 42
                }
                {
                  "type_alias": "thing",
                  "name": "two",
                  "age": 37
                }
                """)) as address_map:

            self.assertEqual(
                {
                    "one": Thing(name="one", age=42),
                    "two": Thing(name="two", age=37)
                },
                address_map.objects_by_name,
            )

    def test_not_serializable(self) -> None:
        with self.assertRaises(UnaddressableObjectError):
            with self.parse_address_map("{}"):
                self.fail()

    def test_not_named(self) -> None:
        with self.assertRaises(UnaddressableObjectError):
            with self.parse_address_map('{"type_alias": "thing"}'):
                self.fail()

    def test_duplicate_names(self) -> None:
        with self.assertRaises(DuplicateNameError):
            with self.parse_address_map(
                    '{"type_alias": "thing", "name": "one"}'
                    '{"type_alias": "thing", "name": "one"}'):
                self.fail()
예제 #5
0
 def test_empty(self) -> None:
     """Test that parsing an empty BUILD file results in an empty AddressFamily."""
     address_mapper = AddressMapper(JsonParser(TEST_TABLE))
     af = run_rule(
         parse_address_family,
         rule_args=[address_mapper, Dir("/dev/null")],
         mock_gets=[
             MockGet(
                 product_type=Snapshot,
                 subject_type=PathGlobs,
                 mock=lambda _: Snapshot(Digest("abc", 10),
                                         ("/dev/null/BUILD", ), ()),
             ),
             MockGet(
                 product_type=FilesContent,
                 subject_type=Digest,
                 mock=lambda _: FilesContent(
                     [FileContent(path="/dev/null/BUILD", content=b"")]),
             ),
         ],
     )
     self.assertEqual(len(af.objects_by_name), 0)
예제 #6
0
 def _address_mapper(self) -> AddressMapper:
     return AddressMapper(JsonParser(TEST_TABLE))
예제 #7
0
 def create_json(self) -> SchedulerSession:
     return self.create(build_patterns=("*.BUILD.json", ),
                        parser=JsonParser(TEST_TABLE))
예제 #8
0
 def _address_mapper(self) -> AddressMapper:
     return AddressMapper(JsonParser(TEST_TABLE), prelude_glob_patterns=())
예제 #9
0
 def _address_mapper(self) -> AddressMapper:
     return AddressMapper(
         JsonParser(TEST_TABLE),
         prelude_glob_patterns=(),
         build_file_imports_behavior=BuildFileImportsBehavior.error,
     )