# Path: xmanager/xm_local/packaging/bazel_tools.py
# _BAZEL_COMMAND = flags.DEFINE_string('xm_bazel_command', 'bazel',
#                                      'A command that runs Bazel.')
# _NAME_RE = '[^:/.*]+'
# _LABEL_LEXER = re.compile(
#     f'^//(?P<packages>{_NAME_RE}(/{_NAME_RE})*)?(?P<target>:{_NAME_RE})?$')
# _EXECUTABLE_COLLECTOR = pattern_matching.match(
#     _collect_bazel_binary,
#     _collect_bazel_container,
#     _return_empty_list,
# )
# def _get_important_outputs(events: Sequence[bes_pb2.BuildEvent],
#                            labels: Sequence[str]) -> List[List[bes_pb2.File]]:
# def _get_normalized_labels(events: Sequence[bes_pb2.BuildEvent],
#                            labels: Sequence[str]) -> List[str]:
# def _get_workspace_directory(events: Sequence[bes_pb2.BuildEvent]) -> str:
# def _read_build_events(path: str) -> List[bes_pb2.BuildEvent]:
# def _root_absolute_path() -> str:
# def _build_multiple_targets(
#     labels: Sequence[str], bazel_args: Sequence[str] = ()) -> List[List[str]]:
# def _lex_label(label: str) -> _LexedLabel:
# def _assemble_label(parts: _LexedLabel) -> str:
# def _label_kind_lines_to_dict(lines: Sequence[str]) -> Dict[str, str]:
#   def fetch_kinds(self, labels: Sequence[str]) -> List[str]:
#   def build_targets(self, labels: Sequence[str],
#                     bazel_args: Sequence[str]) -> List[List[str]]:
# def local_bazel_service() -> LocalBazelService:
# def _collect_bazel_binary(
#     executable: xm.BazelBinary) -> List[client.BazelTarget]:
# def _collect_bazel_container(
#     executable: xm.BazelContainer) -> List[client.BazelTarget]:
# def _return_empty_list(_: xm.ExecutableSpec) -> List[client.BazelTarget]:
# def collect_bazel_targets(
#     packageables: Sequence[xm.Packageable]) -> List[client.BazelTarget]:
# class LocalBazelService(client.BazelService):


import unittest
from xmanager.xm_local.packaging import bazel_tools
# See the License for the specific language governing permissions and
# limitations under the License.




class BazelToolsTest(unittest.TestCase):

  def test_lex_full_label(self):
    self.assertEqual(
        bazel_tools._lex_label('//project/directory:target'),
        (['project', 'directory'], 'target'))

  def test_lex_short_label(self):
    self.assertEqual(
        bazel_tools._lex_label('//project/package'),
        (['project', 'package'], 'package'))

  def test_lex_root_target(self):
    self.assertEqual(bazel_tools._lex_label('//:label'), ([], 'label'))

  def test_lex_empty_label(self):
    with self.assertRaises(ValueError):
      bazel_tools._lex_label('//')

  def test_lex_relative_label(self):
    with self.assertRaises(ValueError):
      bazel_tools._lex_label('a/b:c')

  def test_assemble_label(self):

# Path: xmanager/xm_local/packaging/bazel_tools.py
# _BAZEL_COMMAND = flags.DEFINE_string('xm_bazel_command', 'bazel',
#                                      'A command that runs Bazel.')
# _NAME_RE = '[^:/.*]+'
# _LABEL_LEXER = re.compile(
#     f'^//(?P<packages>{_NAME_RE}(/{_NAME_RE})*)?(?P<target>:{_NAME_RE})?$')
# _EXECUTABLE_COLLECTOR = pattern_matching.match(
#     _collect_bazel_binary,
#     _collect_bazel_container,
#     _return_empty_list,
# )
# def _get_important_outputs(events: Sequence[bes_pb2.BuildEvent],
#                            labels: Sequence[str]) -> List[List[bes_pb2.File]]:
# def _get_normalized_labels(events: Sequence[bes_pb2.BuildEvent],
#                            labels: Sequence[str]) -> List[str]:
# def _get_workspace_directory(events: Sequence[bes_pb2.BuildEvent]) -> str:
# def _read_build_events(path: str) -> List[bes_pb2.BuildEvent]:
# def _root_absolute_path() -> str:
# def _build_multiple_targets(
#     labels: Sequence[str], bazel_args: Sequence[str] = ()) -> List[List[str]]:
# def _lex_label(label: str) -> _LexedLabel:
# def _assemble_label(parts: _LexedLabel) -> str:
# def _label_kind_lines_to_dict(lines: Sequence[str]) -> Dict[str, str]:
#   def fetch_kinds(self, labels: Sequence[str]) -> List[str]:
#   def build_targets(self, labels: Sequence[str],
#                     bazel_args: Sequence[str]) -> List[List[str]]:
# def local_bazel_service() -> LocalBazelService:
# def _collect_bazel_binary(
#     executable: xm.BazelBinary) -> List[client.BazelTarget]:
# def _collect_bazel_container(
#     executable: xm.BazelContainer) -> List[client.BazelTarget]:
# def _return_empty_list(_: xm.ExecutableSpec) -> List[client.BazelTarget]:
# def collect_bazel_targets(
#     packageables: Sequence[xm.Packageable]) -> List[client.BazelTarget]:
# class LocalBazelService(client.BazelService):


# Path: xmanager/xm_local/packaging/bazel_tools_test.py
import unittest
from xmanager.xm_local.packaging import bazel_tools

# See the License for the specific language governing permissions and
# limitations under the License.




class BazelToolsTest(unittest.TestCase):

  def test_lex_full_label(self):
    self.assertEqual(
        bazel_tools._lex_label('//project/directory:target'),
        (['project', 'directory'], 'target'))

  def test_lex_short_label(self):
    self.assertEqual(
        bazel_tools._lex_label('//project/package'),
        (['project', 'package'], 'package'))

  def test_lex_root_target(self):
    self.assertEqual(bazel_tools._lex_label('//:label'), ([], 'label'))

  def test_lex_empty_label(self):
    with self.assertRaises(ValueError):
      bazel_tools._lex_label('//')

  def test_lex_relative_label(self):
    with self.assertRaises(ValueError):
      bazel_tools._lex_label('a/b:c')

  def test_assemble_label(self):

    self.assertEqual(bazel_tools._assemble_label((['a', 'b'], 'c')), '//a/b:c')