code: def test_run(self):
      self.__setup()
      # 0) Test failure case without command and without interactive
      # 1) Test success case with default values and env def file
      # 2) Test failure case if running same task (conflicting containers)
      # 3) Test failure case if running same task with snapshot_dict (conflicting containers)
      # 4) Test success case with snapshot_dict
      # 5) Test success case with saved file during task run
      # 6) Test success case with data file path being passed
      # 7) Test success case with data directory path being passed
  
      # TODO: look into log filepath randomness, sometimes logs are not written
  
      # Create task in the project
      task_obj = self.task_controller.create()
  
      # Create environment definition
      env_def_path = os.path.join(
          self.project_controller.home, "Dockerfile"
      )
      with open(env_def_path, "wb") as f:
          f.write(to_bytes("FROM python:3.5-alpine"))
  
      # 0) Test option 0
      failed = False
      try:
          self.task_controller.run(task_obj.id)
      except RequiredArgumentMissing:
          failed = True
      assert failed
  
      failed = False
      try:
          self.task_controller.run(
              task_obj.id,
              task_dict={
                  "command": None,
                  "interactive": False,
                  "ports": None,
              },
          )
      except RequiredArgumentMissing:
          failed = True
      assert failed
  
      # Create task_dict
      task_command = ["sh", "-c", "echo accuracy:0.45"]
      task_dict = {"command_list": task_command}
  
      # 1) Test option 1
      updated_task_obj = self.task_controller.run(
          task_obj.id, task_dict=task_dict
      )
      after_snapshot_obj = self.task_controller.dal.snapshot.get_by_id(
          updated_task_obj.after_snapshot_id
      )
      environment_obj = self.task_controller.dal.environment.get_by_id(
          after_snapshot_obj.environment_id
      )
      self.environment_ids.append(environment_obj.id)
  
      assert isinstance(updated_task_obj, Task)
      assert task_obj.id == updated_task_obj.id
  
      assert updated_task_obj.before_snapshot_id
      assert updated_task_obj.ports == None
      assert updated_task_obj.interactive == False
      assert updated_task_obj.task_dirpath
      assert updated_task_obj.log_filepath
      assert updated_task_obj.start_time
  
      assert updated_task_obj.after_snapshot_id
      assert updated_task_obj.run_id
      assert updated_task_obj.logs
      assert "accuracy" in updated_task_obj.logs
      assert updated_task_obj.results
      assert updated_task_obj.results == {"accuracy": "0.45"}
      assert after_snapshot_obj.stats == {"accuracy": "0.45"}
      assert updated_task_obj.status == "SUCCESS"
      assert updated_task_obj.end_time
      assert updated_task_obj.duration
  
      self.task_controller.stop(task_obj.id)
  
      # 2) Test option 2
      failed = False
      try:
          self.task_controller.run(task_obj.id)
      except TaskRunError:
          failed = True
      assert failed
  
      # 3) Test option 3
  
      # Create files to add
      self.project_controller.file_driver.create(
          "dirpath1", directory=True
      )
      self.project_controller.file_driver.create(
          "dirpath2", directory=True
      )
      self.project_controller.file_driver.create("filepath1")
  
      # Snapshot dictionary
      snapshot_dict = {
          "paths": [
              os.path.join(self.project_controller.home, "dirpath1"),
              os.path.join(self.project_controller.home, "dirpath2"),
              os.path.join(self.project_controller.home, "filepath1"),
          ],
      }
  
      # Run a basic task in the project
      failed = False
      try:
          self.task_controller.run(
              task_obj.id, snapshot_dict=snapshot_dict
          )
      except TaskRunError:
          failed = True
      assert failed
  
      # Test when the specific task id is already RUNNING
      # Create task in the project
      task_obj_1 = self.task_controller.create()
      self.task_controller.dal.task.update(
          {"id": task_obj_1.id, "status": "RUNNING"}
      )
      # Create environment_driver definition
      env_def_path = os.path.join(
          self.project_controller.home, "Dockerfile"
      )
      with open(env_def_path, "wb") as f:
          f.write(to_bytes("FROM python:3.5-alpine"))
  
      failed = False
      try:
          self.task_controller.run(task_obj_1.id, task_dict=task_dict)
      except TaskRunError:
          failed = True
      assert failed
  
      # 4) Test option 4
  
      # Create a new task in the project
      task_obj_2 = self.task_controller.create()
  
      # Run another task in the project
      updated_task_obj_2 = self.task_controller.run(
          task_obj_2.id,
          task_dict=task_dict,
          snapshot_dict=snapshot_dict,
      )
      after_snapshot_obj = self.task_controller.dal.snapshot.get_by_id(
          updated_task_obj_2.after_snapshot_id
      )
      environment_obj = self.task_controller.dal.environment.get_by_id(
          after_snapshot_obj.environment_id
      )
      self.environment_ids.append(environment_obj.id)
  
      assert isinstance(updated_task_obj_2, Task)
      assert task_obj_2.id == updated_task_obj_2.id
  
      assert updated_task_obj_2.before_snapshot_id
      assert updated_task_obj_2.ports == None
      assert updated_task_obj_2.interactive == False
      assert updated_task_obj_2.task_dirpath
      assert updated_task_obj_2.log_filepath
      assert updated_task_obj_2.start_time
  
      assert updated_task_obj_2.after_snapshot_id
      assert updated_task_obj_2.run_id
      assert updated_task_obj_2.logs
      assert "accuracy" in updated_task_obj_2.logs
      assert updated_task_obj_2.results
      assert updated_task_obj_2.results == {"accuracy": "0.45"}
      assert updated_task_obj_2.status == "SUCCESS"
      assert updated_task_obj_2.end_time
      assert updated_task_obj_2.duration
  
      self.task_controller.stop(task_obj_2.id)
  
      # 5) Test option 5
  
      # Create a basic script
      test_filepath = os.path.join(self.temp_dir, "script.py")
      with open(test_filepath, "wb") as f:
          f.write(to_bytes("import os\n"))
          f.write(to_bytes("import shutil\n"))
          f.write(to_bytes("print('hello')\n"))
          f.write(to_bytes("print(' accuracy: 0.56 ')\n"))
          f.write(
              to_bytes(
                  "with open(os.path.join('/task', 'new_file.txt'), 'a') as f:\n"
              )
          )
          f.write(to_bytes("    f.write('my test file')\n"))
  
      # Create task in the project
      task_obj_2 = self.task_controller.create()
  
      # Create task_dict
      task_command = ["python", "script.py"]
      task_dict = {"command_list": task_command}
  
      # Create environment definition
      env_def_path = os.path.join(
          self.project_controller.home, "Dockerfile"
      )
      with open(env_def_path, "wb") as f:
          f.write(to_bytes("FROM python:3.5-alpine"))
  
      updated_task_obj_2 = self.task_controller.run(
          task_obj_2.id, task_dict=task_dict
      )
      after_snapshot_obj = self.task_controller.dal.snapshot.get_by_id(
          updated_task_obj_2.after_snapshot_id
      )
      environment_obj = self.task_controller.dal.environment.get_by_id(
          after_snapshot_obj.environment_id
      )
      self.environment_ids.append(environment_obj.id)
  
      assert isinstance(updated_task_obj_2, Task)
      assert updated_task_obj_2.before_snapshot_id
      assert updated_task_obj_2.ports == None
      assert updated_task_obj_2.interactive == False
      assert updated_task_obj_2.task_dirpath
      assert updated_task_obj_2.log_filepath
      assert updated_task_obj_2.start_time
  
      assert updated_task_obj_2.after_snapshot_id
      assert updated_task_obj_2.run_id
      assert updated_task_obj_2.logs
      assert "accuracy" in updated_task_obj_2.logs
      assert updated_task_obj_2.results
      assert updated_task_obj_2.results == {"accuracy": "0.56"}
      assert updated_task_obj_2.status == "SUCCESS"
      assert updated_task_obj_2.end_time
      assert updated_task_obj_2.duration
  
      self.task_controller.stop(task_obj_2.id)
  
      # test if after snapshot has the file written
      after_snapshot_obj = self.task_controller.dal.snapshot.get_by_id(
          updated_task_obj_2.after_snapshot_id
      )
      file_collection_obj = (
          self.task_controller.dal.file_collection.get_by_id(
              after_snapshot_obj.file_collection_id
          )
      )
      files_absolute_path = os.path.join(
          self.task_controller.home, file_collection_obj.path
      )
  
      assert os.path.isfile(
          os.path.join(files_absolute_path, "task.log")
      )
      assert os.path.isfile(
          os.path.join(files_absolute_path, "new_file.txt")
      )
  
      # 6) Test Option 6
      self.project_controller.file_driver.create(
          "dirpath1", directory=True
      )
      self.project_controller.file_driver.create(
          os.path.join("dirpath1", "file.txt")
      )
      with open(
          os.path.join(
              self.project_controller.home, "dirpath1", "file.txt"
          ),
          "wb",
      ) as f:
          f.write(to_bytes("my initial line\n"))
      test_filename = "script.py"
      test_filepath = os.path.join(self.temp_dir, test_filename)
      with open(test_filepath, "wb") as f:
          f.write(to_bytes("import os\n"))
          f.write(to_bytes("print('hello')\n"))
          f.write(to_bytes("import shutil\n"))
  
          f.write(
              to_bytes(
                  "with open(os.path.join('/data', 'file.txt'), 'a') as f:\n"
              )
          )
          f.write(to_bytes("    f.write('my test file')\n"))
  
      # Create task in the project
      task_obj_3 = self.task_controller.create()
  
      # Create task_dict
      task_command = ["python", test_filename]
      task_dict = {
          "command_list": task_command,
          "data_file_path_map": [
              (
                  os.path.join(
                      self.project_controller.home,
                      "dirpath1",
                      "file.txt",
                  ),
                  "file.txt",
              )
          ],
      }
  
      # Create environment definition
      env_def_path = os.path.join(
          self.project_controller.home, "Dockerfile"
      )
      with open(env_def_path, "wb") as f:
          f.write(to_bytes("FROM python:3.5-alpine"))
  
      updated_task_obj_3 = self.task_controller.run(
          task_obj_3.id, task_dict=task_dict
      )
      after_snapshot_obj = self.task_controller.dal.snapshot.get_by_id(
          updated_task_obj_3.after_snapshot_id
      )
      environment_obj = self.task_controller.dal.environment.get_by_id(
          after_snapshot_obj.environment_id
      )
      self.environment_ids.append(environment_obj.id)
  
      assert isinstance(updated_task_obj_3, Task)
      assert updated_task_obj_3.before_snapshot_id
      assert updated_task_obj_3.ports == None
      assert updated_task_obj_3.interactive == False
      assert updated_task_obj_3.task_dirpath
      assert updated_task_obj_3.log_filepath
      assert updated_task_obj_3.start_time
  
      assert updated_task_obj_3.after_snapshot_id
      assert updated_task_obj_3.run_id
      assert updated_task_obj_3.logs
      assert updated_task_obj_3.status == "SUCCESS"
      assert updated_task_obj_3.end_time
      assert updated_task_obj_3.duration
  
      self.task_controller.stop(task_obj_3.id)
  
      # test if after snapshot has the file written
      after_snapshot_obj = self.task_controller.dal.snapshot.get_by_id(
          updated_task_obj_3.after_snapshot_id
      )
      file_collection_obj = (
          self.task_controller.dal.file_collection.get_by_id(
              after_snapshot_obj.file_collection_id
          )
      )
      files_absolute_path = os.path.join(
          self.task_controller.home, file_collection_obj.path
      )
  
      assert os.path.isfile(
          os.path.join(files_absolute_path, "task.log")
      )
      assert os.path.isfile(
          os.path.join(
              self.project_controller.home, "dirpath1", "file.txt"
          )
      )
      assert (
          "my initial line"
          in open(
              os.path.join(
                  self.project_controller.home, "dirpath1", "file.txt"
              ),
              "r",
          ).read()
      )
      assert (
          "my test file"
          in open(
              os.path.join(
                  self.project_controller.home, "dirpath1", "file.txt"
              ),
              "r",
          ).read()
      )
  
      # 7) Test Option 7
      self.project_controller.file_driver.create(
          "dirpath1", directory=True
      )
      self.project_controller.file_driver.create(
          os.path.join("dirpath1", "file.txt")
      )
      with open(
          os.path.join(
              self.project_controller.home, "dirpath1", "file.txt"
          ),
          "wb",
      ) as f:
          f.write(to_bytes("my initial line\n"))
      test_filename = "script.py"
      test_filepath = os.path.join(self.temp_dir, test_filename)
      with open(test_filepath, "wb") as f:
          f.write(to_bytes("import os\n"))
          f.write(to_bytes("print('hello')\n"))
          f.write(to_bytes("import shutil\n"))
  
          f.write(
              to_bytes(
                  "with open(os.path.join('/data', 'dirpath1', 'file.txt'), 'a') as f:\n"
              )
          )
          f.write(to_bytes("    f.write('my test file')\n"))
  
      # Create task in the project
      task_obj_4 = self.task_controller.create()
  
      # Create task_dict
      task_command = ["python", test_filename]
      task_dict = {
          "command_list": task_command,
          "data_directory_path_map": [
              (
                  os.path.join(
                      self.project_controller.home, "dirpath1"
                  ),
                  "dirpath1",
              )
          ],
      }
  
      # Create environment definition
      env_def_path = os.path.join(
          self.project_controller.home, "Dockerfile"
      )
      with open(env_def_path, "wb") as f:
          f.write(to_bytes("FROM python:3.5-alpine"))
  
      updated_task_obj_4 = self.task_controller.run(
          task_obj_4.id, task_dict=task_dict
      )
      after_snapshot_obj = self.task_controller.dal.snapshot.get_by_id(
          updated_task_obj_4.after_snapshot_id
      )
      environment_obj = self.task_controller.dal.environment.get_by_id(
          after_snapshot_obj.environment_id
      )
      self.environment_ids.append(environment_obj.id)
  
      assert isinstance(updated_task_obj_4, Task)
      assert updated_task_obj_4.before_snapshot_id
      assert updated_task_obj_4.ports == None
      assert updated_task_obj_4.interactive == False
      assert updated_task_obj_4.task_dirpath
      assert updated_task_obj_4.log_filepath
      assert updated_task_obj_4.start_time
  
      assert updated_task_obj_4.after_snapshot_id
      assert updated_task_obj_4.run_id
      assert updated_task_obj_4.logs
      assert updated_task_obj_4.status == "SUCCESS"
      assert updated_task_obj_4.end_time
      assert updated_task_obj_4.duration
  
      self.task_controller.stop(task_obj_4.id)
  
      # test if after snapshot has the file written
      after_snapshot_obj = self.task_controller.dal.snapshot.get_by_id(
          updated_task_obj_4.after_snapshot_id
      )
      file_collection_obj = (
          self.task_controller.dal.file_collection.get_by_id(
              after_snapshot_obj.file_collection_id
          )
      )
      files_absolute_path = os.path.join(
          self.task_controller.home, file_collection_obj.path
      )
  
      assert os.path.isfile(
          os.path.join(files_absolute_path, "task.log")
      )
      assert os.path.isfile(
          os.path.join(
              self.project_controller.home, "dirpath1", "file.txt"
          )
      )
      assert (
          "my initial line"
          in open(
              os.path.join(
                  self.project_controller.home, "dirpath1", "file.txt"
              ),
              "r",
          ).read()
      )
      assert (
          "my test file"
          in open(
              os.path.join(
                  self.project_controller.home, "dirpath1", "file.txt"
              ),
              "r",
          ).read()
      )
  
imports: import os
  import uuid
  import tempfile
  import platform
  from io import open, TextIOWrapper
  from datmo.config import Config
  from datmo.core.controller.project import ProjectController
  from datmo.core.controller.environment.environment import EnvironmentController
  from datmo.core.controller.task import TaskController
  from datmo.core.entity.task import Task
  from datmo.core.util.exceptions import EntityNotFound, TaskRunError, InvalidArgumentType, RequiredArgumentMissing, ProjectNotInitialized, InvalidProjectPath, TooManyArgumentsFound, DoesNotExist
  from datmo.core.util.misc_functions import check_docker_inactive, pytest_docker_environment_failed_instantiation
label_desc: Use image node_id 10 for calling the TestTaskController obj's underlying member method code with example usage: obj.test_run() without return types