def test_fails_on_nonexistent_specs(self) -> None:
        """Test that address specs referring to nonexistent targets raise a ResolveError."""
        address_family = AddressFamily('root',
                                       {'a': ('root/BUILD', TargetAdaptor())})
        address_specs = AddressSpecs(
            [SingleAddress('root', 'b'),
             SingleAddress('root', 'a')])

        expected_rx_str = re.escape(
            """"b" was not found in namespace "root". Did you mean one of:
  :a""")
        with self.assertRaisesRegex(ResolveError, expected_rx_str):
            self._resolve_build_file_addresses(address_specs, address_family,
                                               self._snapshot(),
                                               self._address_mapper())

        # Ensure that we still catch nonexistent targets later on in the list of command-line
        # address specs.
        address_specs = AddressSpecs(
            [SingleAddress('root', 'a'),
             SingleAddress('root', 'b')])
        with self.assertRaisesRegex(ResolveError, expected_rx_str):
            self._resolve_build_file_addresses(address_specs, address_family,
                                               self._snapshot(),
                                               self._address_mapper())
Exemple #2
0
    def test_exclude_pattern_with_single_address(self) -> None:
        """Test that single address targets are filtered based on exclude patterns."""
        address_specs = AddressSpecs([SingleAddress("root", "not_me")],
                                     exclude_patterns=tuple(["root.*"]))
        address_family = AddressFamily(
            "root", {"not_me": ("root/BUILD", TargetAdaptor())})

        targets = self._resolve_addresses(address_specs, address_family,
                                          self._snapshot(),
                                          self._address_mapper())

        self.assertEqual(len(targets.dependencies), 0)
  def test_duplicated(self):
    """Test that matching the same Spec twice succeeds."""
    address = SingleAddress('a', 'a')
    snapshot = Snapshot(Digest('xx', 2), ('a/BUILD',), ())
    address_family = AddressFamily('a', {'a': ('a/BUILD', 'this is an object!')})
    specs = Specs([address, address])

    bfas = self._resolve_build_file_addresses(
      specs, address_family, snapshot, self._address_mapper())

    self.assertEqual(len(bfas.dependencies), 1)
    self.assertEqual(bfas.dependencies[0].spec, 'a:a')
Exemple #4
0
  def test_exclude_pattern_with_single_address(self):
    """Test that single address targets are filtered based on exclude patterns."""
    specs = Specs([SingleAddress('root', 'not_me')], exclude_patterns=tuple(['root.*']))
    address_family = AddressFamily('root',
                                   {
                                     'not_me': ('root/BUILD', TargetAdaptor()),
                                   }
    )

    targets = self._resolve_build_file_addresses(
      specs, address_family, self._snapshot(), self._address_mapper())

    self.assertEqual(len(targets.dependencies), 0)
Exemple #5
0
    def test_duplicated(self) -> None:
        """Test that matching the same AddressSpec twice succeeds."""
        address = SingleAddress("a", "a")
        snapshot = Snapshot(Digest("xx", 2), ("a/BUILD", ), ())
        address_family = AddressFamily(
            "a", {"a": ("a/BUILD", "this is an object!")})
        address_specs = AddressSpecs([address, address])

        addresses = self._resolve_addresses(address_specs, address_family,
                                            snapshot, self._address_mapper())

        self.assertEqual(len(addresses.dependencies), 1)
        self.assertEqual(addresses.dependencies[0].spec, "a:a")
Exemple #6
0
  def test_exclude_pattern(self):
    """Test that targets are filtered based on exclude patterns."""
    specs = Specs([SiblingAddresses('root')], exclude_patterns=tuple(['.exclude*']))
    address_family = AddressFamily('root',
                                   {'exclude_me': ('root/BUILD', TargetAdaptor()),
                                    'not_me': ('root/BUILD', TargetAdaptor()),
                                   }
    )

    targets = self._resolve_build_file_addresses(
      specs, address_family, self._snapshot(), self._address_mapper())

    self.assertEqual(len(targets.dependencies), 1)
    self.assertEqual(targets.dependencies[0].spec, 'root:not_me')
Exemple #7
0
  def test_duplicated(self):
    """Test that matching the same Spec twice succeeds."""
    address = SingleAddress('a', 'a')
    address_mapper = AddressMapper(JsonParser(TestTable()))
    snapshot = Snapshot(DirectoryDigest(str('xx'), 2), (Path('a/BUILD', File('a/BUILD')),))
    address_family = AddressFamily('a', {'a': ('a/BUILD', 'this is an object!')})

    bfas = run_rule(addresses_from_address_families, address_mapper, Specs([address, address]), {
        (Snapshot, PathGlobs): lambda _: snapshot,
        (AddressFamily, Dir): lambda _: address_family,
      })

    self.assertEquals(len(bfas.dependencies), 1)
    self.assertEquals(bfas.dependencies[0].spec, 'a:a')
Exemple #8
0
  def test_tag_filter(self):
    """Test that targets are filtered based on `tags`."""
    specs = Specs([SiblingAddresses('root')], tags=['+integration'])
    address_family = AddressFamily('root',
      {'a': ('root/BUILD', TargetAdaptor()),
       'b': ('root/BUILD', TargetAdaptor(tags={'integration'})),
       'c': ('root/BUILD', TargetAdaptor(tags={'not_integration'}))
      }
    )

    targets = self._resolve_build_file_addresses(
      specs, address_family, self._snapshot(), self._address_mapper())

    self.assertEqual(len(targets.dependencies), 1)
    self.assertEqual(targets.dependencies[0].spec, 'root:b')
Exemple #9
0
 def test_exclude_pattern_with_single_address(self):
   """Test that single address targets are filtered based on exclude patterns."""
   spec = SingleAddress('root', 'not_me')
   address_mapper = AddressMapper(JsonParser(TestTable()))
   snapshot = Snapshot(DirectoryDigest('xx', 2),
                       (Path('root/BUILD', File('root/BUILD')),))
   address_family = AddressFamily('root',
     {
      'not_me': ('root/BUILD', TargetAdaptor()),
     }
   )
   targets = run_rule(
     addresses_from_address_families, address_mapper, Specs([spec], exclude_patterns=tuple(['root.*'])),{
     (Snapshot, PathGlobs): lambda _: snapshot,
     (AddressFamily, Dir): lambda _: address_family,
   })
   self.assertEqual(len(targets.dependencies), 0)
Exemple #10
0
    def test_exclude_pattern(self) -> None:
        """Test that targets are filtered based on exclude patterns."""
        address_specs = AddressSpecs([SiblingAddresses("root")],
                                     exclude_patterns=tuple([".exclude*"]))
        address_family = AddressFamily(
            "root",
            {
                "exclude_me": ("root/BUILD", TargetAdaptor()),
                "not_me": ("root/BUILD", TargetAdaptor()),
            },
        )

        targets = self._resolve_addresses(address_specs, address_family,
                                          self._snapshot(),
                                          self._address_mapper())

        self.assertEqual(len(targets.dependencies), 1)
        self.assertEqual(targets.dependencies[0].spec, "root:not_me")
Exemple #11
0
 def test_exclude_pattern(self):
     """Test that targets are filtered based on exclude patterns."""
     spec = SiblingAddresses('root')
     address_mapper = AddressMapper(JsonParser(TestTable()))
     snapshot = Snapshot(DirectoryDigest(text_type('xx'), 2),
                         (Path('root/BUILD', File('root/BUILD')), ))
     address_family = AddressFamily(
         'root', {
             'exclude_me': ('root/BUILD', TargetAdaptor()),
             'not_me': ('root/BUILD', TargetAdaptor()),
         })
     targets = run_rule(
         addresses_from_address_families, address_mapper,
         Specs([spec], exclude_patterns=tuple(['.exclude*'])), {
             (Snapshot, PathGlobs): lambda _: snapshot,
             (AddressFamily, Dir): lambda _: address_family,
         })
     self.assertEquals(len(targets.dependencies), 1)
     self.assertEquals(targets.dependencies[0].spec, 'root:not_me')
Exemple #12
0
    def test_tag_filter(self) -> None:
        """Test that targets are filtered based on `tags`."""
        address_specs = AddressSpecs([SiblingAddresses("root")],
                                     tags=["+integration"])
        address_family = AddressFamily(
            "root",
            {
                "a": ("root/BUILD", TargetAdaptor()),
                "b": ("root/BUILD", TargetAdaptor(tags={"integration"})),
                "c": ("root/BUILD", TargetAdaptor(tags={"not_integration"})),
            },
        )

        targets = self._resolve_addresses(address_specs, address_family,
                                          self._snapshot(),
                                          self._address_mapper())

        self.assertEqual(len(targets.dependencies), 1)
        self.assertEqual(targets.dependencies[0].spec, "root:b")
Exemple #13
0
  def test_tag_filter(self):
    """Test that targets are filtered based on `tags`."""
    spec = SiblingAddresses('root')
    address_mapper = AddressMapper(JsonParser(TestTable()))
    snapshot = Snapshot(DirectoryDigest(str('xx'), 2), (Path('root/BUILD', File('root/BUILD')),))
    address_family = AddressFamily('root',
      {'a': ('root/BUILD', TargetAdaptor()),
       'b': ('root/BUILD', TargetAdaptor(tags={'integration'})),
       'c': ('root/BUILD', TargetAdaptor(tags={'not_integration'}))
      }
    )

    targets = run_rule(
      addresses_from_address_families, address_mapper, Specs([spec], tags=['+integration']), {
      (Snapshot, PathGlobs): lambda _: snapshot,
      (AddressFamily, Dir): lambda _: address_family,
    })

    self.assertEquals(len(targets.dependencies), 1)
    self.assertEquals(targets.dependencies[0].spec, 'root:b')