code: def test_encode_as_list(self):
      # should *fail* when object doesn't have `tolist` method
      objs_without_attr = [
          1,
          "one",
          set(["a", "set"]),
          {"a": "dict"},
          ["a", "list"],
      ]
      for obj in objs_without_attr:
          self.assertRaises(
              utils.NotEncodable,
              utils.PlotlyJSONEncoder.encode_as_list,
              obj,
          )
  
      # should return without exception when obj has `tolist` attr
      expected_res = ["some", "list"]
  
      class ObjWithAttr(object):
          def tolist(self):
              return expected_res
  
      res = utils.PlotlyJSONEncoder.encode_as_list(ObjWithAttr())
      self.assertEqual(res, expected_res)
  
imports: import datetime
  import math
  import decimal
  from datetime import datetime
  from unittest import TestCase
  from time import time
  import pytest
  import numpy
  import pandas
  import pytz
  from pandas.testing import assert_series_equal
  import json
  import os
  import base64
  from plotly import optional_imports, utils
  import plotly.graph_objects
  from plotly.graph_objs import Scatter, Scatter3d, Figure, Data
  from plotly.utils import get_by_path
  from PIL import Image
label_desc: Use image node_id 2 for calling the TestJSONEncoder obj's underlying member method code with example usage: obj.test_encode_as_list() and returns: expected_res