Exemple #1
0
  def test_run_command_caches(self):
    # Put a file into a named cache.
    cache_manager = named_cache.CacheManager(os.path.join(self.root_dir, u'c'))
    install_dir = os.path.join(self.root_dir, u'install')

    with cache_manager.open():
      cache_manager.install(install_dir, 'foo')
      with open(os.path.join(install_dir, 'bar'), 'wb') as f:
        f.write('thecache')
      cache_manager.uninstall(install_dir, 'foo')

    # This runs the command for real.
    self.requests(cost_usd=1, exit_code=0)
    script = (
      'import os\n'
      'print "hi"\n'
      'with open("cache_foo/bar", "rb") as f:\n'
      '  cached = f.read()\n'
      'with open("../../result", "wb") as f:\n'
      '  f.write(cached)\n'
      'with open("cache_foo/bar", "wb") as f:\n'
      '  f.write("updated_cache")\n'
    )
    task_details = self.get_task_details(
        script,
        caches=[{'name': 'foo', 'path': 'cache_foo'}])
    expected = {
      u'exit_code': 0,
      u'hard_timeout': False,
      u'io_timeout': False,
      u'must_signal_internal_failure': None,
      u'version': task_runner.OUT_VERSION,
    }
    self.assertEqual(expected, self._run_command(task_details))

    with open(os.path.join(self.root_dir, 'result'), 'rb') as f:
      self.assertEqual('thecache', f.read())

    with cache_manager.open():
      cache_manager.install(install_dir, 'foo')
      with open(os.path.join(install_dir, 'bar'), 'rb') as f:
        self.assertEqual('updated_cache', f.read())
      cache_manager.uninstall(install_dir, 'foo')
Exemple #2
0
 def setUp(self):
   self.tempdir = tempfile.mkdtemp(prefix=u'named_cache_test')
   self.manager = named_cache.CacheManager(self.tempdir)