    def test_external_tensor_is_constant(self, test_name="external_tensor_is_constant"):
        """
        Case: The intermediate tensor is a view of a constant.
        Graph: ( constant ) <--view-- ( intermediate ) <--view-- ( output_0 )
        Expect: The intermediate tensor is constant folded.
        """
        constant = Tensor(
            shape=self.SHAPE, dtype="float16", name="constant"
        )  # has an output alias
        intermediate_view = ops.unsqueeze(dim=0)(constant)  # has an output alias
        output0 = ops.flatten()(intermediate_view)
        output0._attrs["is_output"] = True
        output0._attrs["name"] = "output_0"

        constant_pt = get_random_torch_tensor(self.SHAPE, dtype="float16")

        compile_model(
            output0,
            detect_target(),
            self.WORKDIR,
            test_name,
            constants={"constant": constant_pt},
            do_optimize_graph=False,
        )
        intermediate_view_name = intermediate_view._attrs["name"]
        expected_codegen = (
            set_value(intermediate_view_name, "constant"),
            set_value("output_0", intermediate_view_name),
        )
        # We expect the intermediate tensor and output_0 to be constant folded.
        # So, we don't expect _codegen_output_aliases_tensor to be called.
        self._assert_codegen_exists(
            test_name, expected_codegen, self.MODEL_GENERATED_FILE, exists=False
        )
Case: The intermediate tensor is a view of a constant.
Graph: ( constant ) <--view-- ( intermediate ) <--view-- ( output_0 )
Expect: The intermediate tensor is constant folded.
tests/unittest/backend/test_codegen_output_aliases.py