code: def test_clean_keep_last(self):
      first = self._empty_ingest()
  
      assert_equal(
          self.clean("bundle", keep_last=1, environ=self.environ),
          set(),
      )
      assert_equal(
          self._list_bundle(),
          {first},
          msg="directory should not have changed",
      )
  
      second = self._empty_ingest()
      assert_equal(
          self._list_bundle(),
          {first, second},
          msg="two ingestions are not present",
      )
      assert_equal(
          self.clean("bundle", keep_last=1, environ=self.environ),
          {first},
      )
      assert_equal(
          self._list_bundle(),
          {second},
          msg="first ingestion was not removed with keep_last=2",
      )
  
      third = self._empty_ingest()
      fourth = self._empty_ingest()
      fifth = self._empty_ingest()
  
      assert_equal(
          self._list_bundle(),
          {second, third, fourth, fifth},
          msg="larger set of ingestions did not happen correctly",
      )
  
      assert_equal(
          self.clean("bundle", keep_last=2, environ=self.environ),
          {second, third},
      )
  
      assert_equal(
          self._list_bundle(),
          {fourth, fifth},
          msg="keep_last=2 did not remove the correct number of ingestions",
      )
  
      with assert_raises(BadClean):
          self.clean("bundle", keep_last=-1, environ=self.environ)
  
      assert_equal(
          self._list_bundle(),
          {fourth, fifth},
          msg="keep_last=-1 removed some ingestions",
      )
  
      assert_equal(
          self.clean("bundle", keep_last=0, environ=self.environ),
          {fourth, fifth},
      )
  
      assert_equal(
          self._list_bundle(),
          set(),
          msg="keep_last=0 did not remove the correct number of ingestions",
      )
  
imports: import os
  from nose_parameterized import parameterized
  import pandas
  import sqlalchemy
  from toolz import valmap
  import toolz.curried.operator
  from trading_calendars import TradingCalendar, get_calendar
  from zipline.assets import ASSET_DB_VERSION
  from zipline.assets.asset_writer import check_version_info
  from zipline.assets.synthetic import make_simple_equity_info
  from zipline.data.bundles import UnknownBundle, from_bundle_ingest_dirname, ingestions_for_bundle
  from zipline.data.bundles.core import _make_bundle_core, BadClean, to_bundle_ingest_dirname, asset_db_path
  from zipline.lib.adjustment import Float64Multiply
  from zipline.pipeline.loaders.synthetic import make_bar_data, expected_bar_values_2d
  from zipline.testing import subtest, str_to_seconds
  from zipline.testing.fixtures import WithInstanceTmpDir, ZiplineTestCase, WithDefaultDateBounds
  from zipline.testing.predicates import assert_equal, assert_false, assert_in, assert_is, assert_is_instance, assert_is_none, assert_raises, assert_true
  from zipline.utils.cache import dataframe_cache
  from zipline.utils.functional import apply
  import zipline.utils.paths
label_desc: Use image node_id 12 for calling the BundleCoreTestCase obj's underlying member method code with example usage: obj.test_clean_keep_last() without return types