Пример #1
0
 def test_have_sources(self):
     action = action_tracer.Action(script="script.sh",
                                   sources=["input.src", "main.h"])
     self.assertEqual(
         action.access_constraints(),
         action_tracer.AccessConstraints(
             allowed_reads=abspaths({"script.sh", "input.src", "main.h"})))
Пример #2
0
 def test_have_response_file(self):
     action = action_tracer.Action(script="script.sh",
                                   response_file_name="response.out")
     self.assertEqual(
         action.access_constraints(),
         action_tracer.AccessConstraints(
             allowed_reads=abspaths({"script.sh", "response.out"})))
Пример #3
0
    def test_links_are_followed(self):

        def fake_realpath(s: str) -> str:
            return f'test/realpath/{s}'

        action = action_tracer.Action(inputs=["script.sh"], depfile="foo.d")
        with mock.patch.object(os.path, 'exists',
                               return_value=True) as mock_exists:
            with mock.patch("builtins.open", mock.mock_open(
                    read_data="foo.o: foo.cc foo.h\n")) as mock_file:
                with mock.patch.object(os.path, 'realpath',
                                       wraps=fake_realpath) as mock_realpath:
                    constraints = action.access_constraints(
                        writeable_depfile_inputs=False)
        mock_exists.assert_called_once()
        mock_file.assert_called_once()
        mock_realpath.assert_called()

        self.assertEqual(
            constraints,
            action_tracer.AccessConstraints(
                allowed_reads=abspaths(
                    {
                        "test/realpath/script.sh",
                        "test/realpath/foo.d",
                        "test/realpath/foo.o",
                        "test/realpath/foo.cc",
                        "test/realpath/foo.h",
                    }),
                allowed_writes=abspaths({"foo.d", "foo.o"})))
Пример #4
0
 def test_have_inputs(self):
     action = action_tracer.Action(
         inputs=["script.sh", "input.txt", "main.cc"])
     self.assertEqual(
         action.access_constraints(),
         action_tracer.AccessConstraints(
             allowed_reads=abspaths({"script.sh", "input.txt", "main.cc"})))
Пример #5
0
 def test_have_outputs(self):
     action = action_tracer.Action(script="script.sh", outputs=["main.o"])
     self.assertEqual(
         action.access_constraints(),
         action_tracer.AccessConstraints(
             allowed_reads=abspaths({"script.sh", "main.o"}),
             allowed_writes=abspaths({"main.o"}),
             required_writes=abspaths({"main.o"})))
Пример #6
0
 def test_have_nonexistent_depfile(self):
     action = action_tracer.Action(depfile="foo.d")
     with mock.patch.object(os.path, 'exists',
                            return_value=False) as mock_exists:
         constraints = action.access_constraints()
     mock_exists.assert_called()
     self.assertEqual(
         constraints,
         action_tracer.AccessConstraints(allowed_writes=abspaths({"foo.d"}),
                                         allowed_reads=abspaths({"foo.d"})))
Пример #7
0
    def test_have_depfile(self):
        action = action_tracer.Action(script="script.sh", depfile="foo.d")
        with mock.patch.object(os.path, 'exists',
                               return_value=True) as mock_exists:
            with mock.patch(
                    "builtins.open",
                    mock.mock_open(
                        read_data="foo.o: foo.cc foo.h\n")) as mock_file:
                constraints = action.access_constraints()

        self.assertEqual(
            constraints,
            action_tracer.AccessConstraints(
                allowed_reads=abspaths(
                    {"script.sh", "foo.d", "foo.o", "foo.cc", "foo.h"}),
                allowed_writes=abspaths({"foo.d", "foo.o", "foo.cc",
                                         "foo.h"})))
Пример #8
0
 def test_empty_action(self):
     action = action_tracer.Action(script="script.sh")
     self.assertEqual(
         action.access_constraints(),
         action_tracer.AccessConstraints(
             allowed_reads=abspaths({"script.sh"})))