def testCloudSdkConfig(self): cwd = 'now-here' env = FakeEnviron() with Stub(os, 'environ', env): with Stub(os, 'getcwd', lambda: cwd): bootstrap.setup_magic_environment(JOB) self.assertTrue(env[bootstrap.CLOUDSDK_ENV].startswith(cwd))
def testWorkspace(self): """WORKSPACE exists, equals HOME and is set to cwd.""" env = FakeEnviron() cwd = '/fake/random-location' with Stub(os, 'environ', env): with Stub(os, 'getcwd', lambda: cwd): bootstrap.setup_magic_environment(JOB) self.assertIn(bootstrap.WORKSPACE_ENV, env) self.assertEquals(env[bootstrap.HOME_ENV], env[bootstrap.WORKSPACE_ENV]) self.assertEquals(cwd, env[bootstrap.WORKSPACE_ENV])
def testExpected(self): env = FakeEnviron() del env[bootstrap.JOB_ENV] del env[bootstrap.NODE_ENV] with Stub(os, 'environ', env): bootstrap.setup_magic_environment(JOB) def Check(name): self.assertIn(name, env) # Some of these are probably silly to check... # TODO(fejta): remove as many of these from our infra as possible. Check(bootstrap.JOB_ENV) Check(bootstrap.CLOUDSDK_ENV) Check(bootstrap.BOOTSTRAP_ENV) Check(bootstrap.WORKSPACE_ENV) Check(bootstrap.SERVICE_ACCOUNT_ENV)
def testJobEnvMismatch(self): env = FakeEnviron() with Stub(os, 'environ', env): with self.assertRaises(ValueError): bootstrap.setup_magic_environment('this-is-a-job')