def test_run(self): cls = attr.make_class('MockSet', ['a']) recipe = cls(types.Value('b')) steps = [types.Step('set', recipe, None)] ctx = phase3.Context() phase3.run(steps, ctx) self.assertEqual(ctx.variables, {'a': 'b'})
def test_handle_create_temp_dir(self): cls = attr.make_class('Mock', ['var']) obj = cls('myVar') ctx = phase3.Context() phase3.handle_create_temp_dir(obj, ctx) path = ctx.variables['myVar'] self.assertTrue(os.path.exists(path)) self.assertEqual(ctx.temp_dirs[0].name, path)
def test_copy_dir_dry(self): self.fs.create_dir('/srcDir') self.fs.create_dir('/dstDir') obj = self.cls(['/srcDir'], '/dstDir') ctx = phase3.Context(dry_run=True) phase3.handle_copy(obj, ctx) self.assertFalse(os.path.exists('/dstDir/srcDir/'))
def test_copy_file(self): self.fs.create_file('/srcFile') self.fs.create_dir('/dstDir') obj = self.cls(['/srcFile'], '/dstDir') ctx = phase3.Context(dry_run=False) phase3.handle_copy(obj, ctx) self.assertTrue(os.path.exists('/dstDir/srcFile'))
def context_command_recorder(): ctx = phase3.Context() ctx.commands = [] def run_cmd(self, *cmd): self.commands.append(cmd) # pylint: disable=assignment-from-no-return ctx.run_cmd = run_cmd.__get__(ctx, phase3.Context) return ctx
def run(path, dry_run): root = load(path) ctx = phase3.Context(dry_run=dry_run) phase3.run(root, ctx)
def test_call(self): ctx = phase3.Context() os.environ['FOO'] = 'bar' call = types.Call('env', ('FOO', )) self.assertEqual(phase3.resolve(types.Value(call), ctx), 'bar')
def test_var(self): ctx = phase3.Context() ctx.variables['foo'] = 'bar' self.assertEqual(phase3.resolve(types.Value(types.Var('foo')), ctx), 'bar')
def test_set(self): cls = attr.make_class('SetMock', ['foo']) obj = cls('bar') ctx = phase3.Context() phase3.handle_set(obj, ctx) self.assertEqual(ctx.variables, {'foo': 'bar'})
def test_run_cmd(self): # pylint: disable=no-self-use ctx = phase3.Context(dry_run=False) ctx.run_cmd('true') ctx.dry_run = True ctx.run_cmd('false')
def test_repath(self): ctx = phase3.Context() ctx.step = types.Step('foo', None, '/base') self.assertEqual(ctx.repath('myPath'), '/base/myPath')