def METHOD_NAME(tmp_path):
    exttree = {
        "cool_stuff": {"a": np.array([0, 1, 2], float), "b": np.array([3, 4, 5], float)},
        "list_of_stuff": ["foobar", 42, np.array([7, 8, 9], float)],
    }
    external_path = os.path.join(str(tmp_path), "external.asdf")
    ext = asdf.AsdfFile(exttree)
    # Since we're testing with small arrays, force all arrays to be stored
    # in internal blocks rather than letting some of them be automatically put
    # inline.
    ext.write_to(external_path, all_array_storage="internal")
    external_path = os.path.join(str(tmp_path), "external2.asdf")
    ff = asdf.AsdfFile(exttree)
    ff.write_to(external_path, all_array_storage="internal")
    tree = {
        # The special name "data" here must be an array.  This is
        # included so that such validation can be ignored when we just
        # have a "$ref".
        "data": {"$ref": "external.asdf#/cool_stuff/a"},
        "science_data": {"$ref": "external.asdf#/cool_stuff/a"},
        "science_data2": {"$ref": "external2.asdf#/cool_stuff/a"},
        "foobar": {
            "$ref": "external.asdf#/list_of_stuff/0",
        },
        "answer": {"$ref": "external.asdf#/list_of_stuff/1"},
        "array": {
            "$ref": "external.asdf#/list_of_stuff/2",
        },
        "whole_thing": {"$ref": "external.asdf#"},
        "myself": {
            "$ref": "#",
        },
        "internal": {"$ref": "#science_data"},
    }
    def do_asserts(ff):
        assert "unloaded" in repr(ff.tree["science_data"])
        assert "unloaded" in str(ff.tree["science_data"])
        assert len(ff._external_asdf_by_uri) == 0
        assert_array_equal(ff.tree["science_data"], exttree["cool_stuff"]["a"])
        assert len(ff._external_asdf_by_uri) == 1
        with pytest.raises((ValueError, RuntimeError), match=r"assignment destination is read-only"):
            # Assignment destination is readonly
            ff.tree["science_data"][0] = 42
        assert_array_equal(ff.tree["science_data2"], exttree["cool_stuff"]["a"])
        assert len(ff._external_asdf_by_uri) == 2
        assert ff.tree["foobar"]() == "foobar"
        assert ff.tree["answer"]() == 42
        assert_array_equal(ff.tree["array"], exttree["list_of_stuff"][2])
        assert_tree_match(ff.tree["whole_thing"](), exttree)
        assert_array_equal(ff.tree["whole_thing"]["cool_stuff"]["a"], exttree["cool_stuff"]["a"])
        assert_array_equal(ff.tree["myself"]["science_data"], exttree["cool_stuff"]["a"])
        # Make sure that referencing oneself doesn't make another call
        # to disk.
        assert len(ff._external_asdf_by_uri) == 2
        assert_array_equal(ff.tree["internal"], exttree["cool_stuff"]["a"])
    with asdf.AsdfFile(tree, uri=util.filepath_to_url(os.path.join(str(tmp_path), "main.asdf"))) as ff:
        do_asserts(ff)
        internal_path = os.path.join(str(tmp_path), "main.asdf")
        ff.write_to(internal_path)
    with asdf.open(internal_path) as ff:
        do_asserts(ff)
    with asdf.open(internal_path) as ff:
        assert len(ff._external_asdf_by_uri) == 0
        ff.resolve_references()
        assert len(ff._external_asdf_by_uri) == 2
        assert isinstance(ff.tree["data"], ndarray.NDArrayType)
        assert isinstance(ff.tree["science_data"], ndarray.NDArrayType)
        assert_array_equal(ff.tree["science_data"], exttree["cool_stuff"]["a"])
        assert_array_equal(ff.tree["science_data2"], exttree["cool_stuff"]["a"])
        assert ff.tree["foobar"] == "foobar"
        assert ff.tree["answer"] == 42
        assert_array_equal(ff.tree["array"], exttree["list_of_stuff"][2])
        assert_tree_match(ff.tree["whole_thing"], exttree)
        assert_array_equal(ff.tree["whole_thing"]["cool_stuff"]["a"], exttree["cool_stuff"]["a"])
        assert_array_equal(ff.tree["myself"]["science_data"], exttree["cool_stuff"]["a"])
        assert_array_equal(ff.tree["internal"], exttree["cool_stuff"]["a"])