예제 #1
0
 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'})
예제 #2
0
 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)
예제 #3
0
    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/'))
예제 #4
0
    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'))
예제 #5
0
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
예제 #6
0
def run(path, dry_run):
    root = load(path)
    ctx = phase3.Context(dry_run=dry_run)
    phase3.run(root, ctx)
예제 #7
0
 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')
예제 #8
0
 def test_var(self):
     ctx = phase3.Context()
     ctx.variables['foo'] = 'bar'
     self.assertEqual(phase3.resolve(types.Value(types.Var('foo')), ctx),
                      'bar')
예제 #9
0
 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'})
예제 #10
0
 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')
예제 #11
0
 def test_repath(self):
     ctx = phase3.Context()
     ctx.step = types.Step('foo', None, '/base')
     self.assertEqual(ctx.repath('myPath'), '/base/myPath')