Пример #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')