code: def _test_split_data_by_edge_type_and_attribute(
      self, g, es_obj, method
  ):
      p = 0.1
      res = es_obj.train_test_split(
          p=p,
          method=method,
          keep_connected=True,
          edge_label="friend",
          edge_attribute_label="date",
          attribute_is_datetime=True,
          edge_attribute_threshold="01/01/2008",
      )
      g_test, edge_data_ids_test, edge_data_labels_test = res
  
      # if all goes well, what are the expected return values?
      num_sampled_positives = np.sum(edge_data_labels_test == 1)
      num_sampled_negatives = np.sum(edge_data_labels_test == 0)
  
      assert num_sampled_positives > 0
      assert num_sampled_negatives > 0
      assert len(edge_data_ids_test) == len(edge_data_labels_test)
      assert (num_sampled_positives - num_sampled_negatives) == 0
      assert len(g_test.edges()) < len(g.edges())
      assert nx.is_connected(g_test)
  
      p = 0.8
      with pytest.raises(ValueError):
          # This will raise ValueError because it cannot sample enough positive edges while maintaining graph
          # connectivity
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="friend",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="01/01/2008",
          )
  
      with pytest.raises(ValueError):
          # This will raise ValueError because it cannot sample enough negative edges of the given edge_label.
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=False,
              edge_label="friend",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="01/01/2008",
          )
  
      p = 0.1
      with pytest.raises(KeyError):
          # This call will raise an exception because the edges of type friend don't have attribute of type 'Any'
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="friend",
              edge_attribute_label="Any",
              attribute_is_datetime=True,
              edge_attribute_threshold="01/01/2008",
          )
      with pytest.raises(KeyError):
          # This call will raise and exception because edges of type 'towards' don't have a 'date' attribute
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="published-at",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="01/01/2008",
          )
  
      with pytest.raises(ValueError):
          # This call will raise an exception because the edge attribute must be specified as datetime
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="friend",
              edge_attribute_label="date",
              attribute_is_datetime=False,
              edge_attribute_threshold="01/01/2008",
          )
  
      # Th below call will raise an exception because the threshold value does not have the correct format dd/mm/yyyy
      with pytest.raises(ValueError):
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="friend",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="01/2008",
          )
      with pytest.raises(ValueError):
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="friend",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="Jan 2005",
          )
      with pytest.raises(ValueError):
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="friend",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="01-01-2000",
          )
      with pytest.raises(ValueError):
          # month is out of range; no such thing as a 14th month in a year
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="friend",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="01/14/2008",
          )
      with pytest.raises(ValueError):
          # day is out of range; no such thing as a 32nd day in October
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="friend",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="32/10/2008",
          )
  
      with pytest.raises(Exception):
          # This call to train_test_split will raise an exception because all the edges of type 'writes' are
          # on the minimum spanning tree and cannot be removed.
          es_obj.train_test_split(
              p=p,
              method=method,
              keep_connected=True,
              edge_label="writes",
              edge_attribute_label="date",
              attribute_is_datetime=True,
              edge_attribute_threshold="01/01/2008",
          )
  
imports: import pytest
  import os
  import numpy
  import networkx
  from stellargraph import StellarGraph
  from stellargraph.data.edge_splitter import EdgeSplitter
  from stellargraph.data.epgm import EPGM
  import random
  import datetime
  from datetime import datetime, timedelta
  from ..test_utils import flaky_xfail_mark
  from ..test_utils.graphs import example_graph_random
label_desc: Use image node_id 2 for calling the TestEdgeSplitterHeterogeneous obj's underlying member method code with example usage: obj._test_split_data_by_edge_type_and_attribute(g, es_obj, method) without return types