def test_used_file(file_name, some_context): ufile = used_file(path=file_name, context=some_context) assert ufile.path == file_name assert ufile.context == some_context ufile = used_file(file_name, some_context) assert ufile.path == file_name assert ufile.context == some_context
def test_ast_to_used_files(file_name): ast = lines_to_ast(( '# some comment', 'run /some/script', 'copy-in /copyed/dir:/dst/dir', 'install sopme-pkg', '', 'root-password file:/root/pwd/file', ), context_file=file_name) expected = ( used_file('/some/script', context(file_name, 2)), used_file('/copyed/dir', context(file_name, 3)), used_file('/root/pwd/file', context(file_name, 6)), ) result = tuple(ast_to_used_files(ast)) assert expected == result
def test_command_to_used_file(file_name): commands = lines_to_ast(( 'upload /copied/file:/dst/path', 'copy-in /copyed/dir:/dst/dir', 'firstboot /some/fb.script', 'password user:file:/user/pwd/file', 'password user:locked:file:/user/pwd/file', 'root-password file:/root/pwd/file', 'root-password locked:file:/root/pwd/file', 'run /some/script', ), context_file=file_name) file_names = ( '/copied/file', '/copyed/dir', '/some/fb.script', '/user/pwd/file', '/user/pwd/file', '/root/pwd/file', '/root/pwd/file', '/some/script', ) for cmd, fname in _it.izip(commands, file_names): expected = used_file(fname, cmd.context) result = command_to_used_file(cmd) assert expected == result no_file_commands = lines_to_ast(( 'chmod 0755:/some/vm/file', 'delete /some/vm/file', 'copy /some/vm/file:/some/othr/vm.file', 'password user:password:/user/pwd/file', 'password user:locked:password:/user/pwd/file', 'root-password password:/root/pwd/file', 'root-password locked:password:/root/pwd/file', )) for cmd in no_file_commands: with pytest.raises(CommandWithoutFile) as err: command_to_used_file(cmd) assert cmd == err.value.command