def test_001(self): """ delete defaults :return: """ HEADING() Var.clear() print (Var.list()) assert Var.list() == None
def test_001(self): """ delete defaults :return: """ HEADING() Var.clear() print(Var.list()) assert Var.list() == None
def test_003(self): HEADING("delete default variable") Var.clear() name = "deleteme" value = "myvalue" Var.set(name, value) print(Var.list()) Var.delete(name) print(Var.list()) self._check("None")
def test_999(self): """ clear the defaults :return: """ HEADING() Var.clear() Var.list() assert True
def test_002(self): HEADING("set default variable") name = "myvar" value = "myvalue" Var.set(name, value) print(Var.list()) self._check(value)
def test_999(self): HEADING("clear the defaults") Var.clear() result = Var.list() print(result) assert result is None
def do_var(self, arg, arguments): """ Usage: var list var delete NAMES var NAME=VALUE var NAME Arguments: NAME Name of the variable NAMES Names of the variable separated by spaces VALUE VALUE to be assigned special vars date and time are defined """ if arguments['list'] or arg == '' or arg is None: # self._list_variables() print(Var.list()) return "" elif arguments['NAME=VALUE'] and "=" in arguments["NAME=VALUE"]: (variable, value) = arg.split('=', 1) if value == "time" or value == "now": value = datetime.datetime.now().strftime("%H:%M:%S") elif value == "date": value = datetime.datetime.now().strftime("%Y-%m-%d") elif value.startswith("default."): name = value.replace("default.", "") value = Default.get(name=name, category="general") elif "." in value: try: config = ConfigDict("cloudmesh.yaml") value = config[value] except Exception as e: Console.error( "can not find variable {} in cloudmesh.yaml".format( value)) value = None # self._add_variable(variable, value) Var.set(variable, value) return "" elif arguments['NAME=VALUE'] and "=" not in arguments["NAME=VALUE"]: try: v = arguments['NAME=VALUE'] # Console.ok(str(self.variables[v])) Console.ok(str(Var.get(v))) except: Console.error('variable {:} not defined'.format( arguments['NAME=VALUE'])) elif arg.startswith('delete'): variable = arg.split(' ')[1] Var.delete(variable) # self._delete_variable(variable) return ""
def test_002(self): """ set default variable :return: """ HEADING() name = "myvar" value = "myvalue" Var.set(name, value) print (Var.list()) assert Var.get(name) == value self._check(value)
def test_002(self): """ set default variable :return: """ HEADING() name = "myvar" value = "myvalue" Var.set(name, value) print(Var.list()) assert Var.get(name) == value self._check(value)
def do_var(self, arg, arguments): """ Usage: var list var delete NAMES var NAME=VALUE var NAME Arguments: NAME Name of the variable NAMES Names of the variable separated by spaces VALUE VALUE to be assigned special vars date and time are defined """ if arguments['list'] or arg == '' or arg is None: # self._list_variables() print(Var.list()) return "" elif arguments['NAME=VALUE'] and "=" in arguments["NAME=VALUE"]: (variable, value) = arg.split('=', 1) if value == "time" or value == "now": value = datetime.datetime.now().strftime("%H:%M:%S") elif value == "date": value = datetime.datetime.now().strftime("%Y-%m-%d") elif value.startswith("default."): name = value.replace("default.", "") value = Default.get(name=name, category="general") elif "." in value: try: config = ConfigDict("cloudmesh.yaml") value = config[value] except Exception as e: Console.error("can not find variable {} in cloudmesh.yaml".format(value)) value = None # self._add_variable(variable, value) Var.set(variable, value) return "" elif arguments['NAME=VALUE'] and "=" not in arguments["NAME=VALUE"]: try: v = arguments['NAME=VALUE'] # Console.ok(str(self.variables[v])) Console.ok(str(Var.get(v))) except: Console.error('variable {:} not defined'.format(arguments['NAME=VALUE'])) elif arg.startswith('delete'): variable = arg.split(' ')[1] Var.delete(variable) # self._delete_variable(variable) return ""
def replace_vars(self, line): self.update_time() newline = line variables = Var.list(format="dict") if len(variables) is not None: for v in variables: name = variables[v]["name"] value = variables[v]["value"] newline = newline.replace("$" + name, value) # for v in os.environ: # newline = newline.replace("$" + v.name, os.environ[v]) newline = path_expand(newline) return newline
def replace_vars(self, line): self.update_time() newline = line variables = Var.list(output='dict') if len(variables) is not None: for v in variables: v = str(v) name = str(variables[v]["name"]) value = str(variables[v]["value"]) newline = newline.replace("$" + name, value) # for v in os.environ: # newline = newline.replace("$" + v.name, os.environ[v]) newline = path_expand(newline) return newline
def _check(self, content): result = Var.list() print(result) assert content in str(result)
def test_001(self): HEADING(" delete defaults") Var.clear() print(Var.list()) assert Var.list() is None