code: def test_upload(unittest):
      import dtale.views as views
      import dtale.global_state as global_state
  
      global_state.clear_store()
      df, _ = views.format_data(pd.DataFrame([1, 2, 3]))
      with build_app(url=URL).test_client() as c:
          build_data_inst({c.port: df})
          global_state.set_dtypes(c.port, views.build_dtypes_state(df))
  
          resp = c.post("/dtale/upload")
          assert not resp.get_json()["success"]
  
          c.post(
              "/dtale/upload",
              data={
                  "tests_df.csv": (build_upload_data(), "test_df.csv"),
                  "separatorType": "csv",
              },
          )
          assert global_state.size() == 2
          new_key = next(
              (k for k in global_state.keys() if k != str(c.port)), None
          )
          assert list(global_state.get_data(new_key).columns) == [
              "a",
              "b",
              "c",
          ]
  
      with build_app(url=URL).test_client() as c:
          global_state.clear_store()
          build_data_inst({c.port: df})
          global_state.set_dtypes(c.port, views.build_dtypes_state(df))
  
          resp = c.post("/dtale/upload")
          assert not resp.get_json()["success"]
  
          c.post(
              "/dtale/upload",
              data={
                  "tests_df.csv": (build_upload_data(), "test_df.csv"),
                  "separatorType": "custom",
                  "separator": ",",
              },
          )
          assert global_state.size() == 2
          new_key = next(
              (k for k in global_state.keys() if k != str(c.port)), None
          )
          assert list(global_state.get_data(new_key).columns) == [
              "a",
              "b",
              "c",
          ]
  
      with build_app(url=URL).test_client() as c:
          global_state.clear_store()
          build_data_inst({c.port: df})
          global_state.set_dtypes(c.port, views.build_dtypes_state(df))
          assert global_state.size() == 1
          if PY3 and check_pandas_version("0.25.0"):
              c.post(
                  "/dtale/upload",
                  data={
                      "test_df.xlsx": (
                          os.path.join(
                              os.path.dirname(__file__),
                              "..",
                              "data/test_df.xlsx",
                          ),
                          "test_df.xlsx",
                      )
                  },
              )
              assert global_state.size() == 2
              new_key = next(
                  (k for k in global_state.keys() if k != str(c.port)),
                  None,
              )
              assert list(global_state.get_data(new_key).columns) == [
                  "a",
                  "b",
                  "c",
              ]
  
      with build_app(url=URL).test_client() as c:
          with ExitStack() as stack:
              global_state.clear_store()
              data = {c.port: df}
              build_data_inst(data)
              global_state.set_dtypes(
                  c.port, views.build_dtypes_state(df)
              )
              stack.enter_context(
                  mock.patch(
                      "dtale.views.pd.read_excel",
                      mock.Mock(
                          return_value={
                              "Sheet 1": pd.DataFrame(
                                  dict(a=[1], b=[2])
                              ),
                              "Sheet 2": pd.DataFrame(
                                  dict(c=[1], d=[2])
                              ),
                          }
                      ),
                  )
              )
              resp = c.post(
                  "/dtale/upload",
                  data={
                      "test_df.xlsx": (
                          os.path.join(
                              os.path.dirname(__file__),
                              "..",
                              "data/test_df.xlsx",
                          ),
                          "test_df.xlsx",
                      )
                  },
              )
              assert global_state.size() == 3
              sheets = resp.json["sheets"]
              assert len(sheets) == 2
              unittest.assertEqual(
                  sorted([s["name"] for s in sheets]),
                  ["Sheet 1", "Sheet 2"],
              )
  
file_path: dtale/tests/dtale/test_upload.py
imports: import os
  import mock
  import pandas
  import pytest
  from six import BytesIO, PY3
  from dtale.app import build_app
  from dtale.pandas_util import check_pandas_version
  from tests import ExitStack
  from tests.dtale import build_data_inst
label_desc: Use image node_id 2 for calling a global function with example usage: test_upload(unittest) without return types