Best Python code snippet using molecule_python
config.py
Source:config.py  
...209        ``get_config`` call.  This is probably __very__ bad.210        :return: dict211        """212        env = util.merge_dicts(os.environ, self.env)213        env = set_env_from_file(env, self.env_file)214        return self._combine(env=env)215    def _combine(self, env=os.environ, keep_string=None):216        """217        Perform a prioritized recursive merge of config files.218        Returns a new dict.  Prior to merging the config files are interpolated with219        environment variables.220        1. Loads Molecule defaults.221        2. Loads a base config (if provided) and merges ontop of defaults.222        3. Loads the scenario's ``molecule file`` and merges ontop of previous223           merge.224        :return: dict225        """226        defaults = self._get_defaults()227        base_config = self.args.get("base_config")228        if base_config and os.path.exists(base_config):229            with util.open_file(base_config) as stream:230                s = stream.read()231                self._preflight(s)232                interpolated_config = self._interpolate(s, env, keep_string)233                defaults = util.merge_dicts(234                    defaults, util.safe_load(interpolated_config)235                )236        if self.molecule_file:237            with util.open_file(self.molecule_file) as stream:238                s = stream.read()239                self._preflight(s)240                interpolated_config = self._interpolate(s, env, keep_string)241                defaults = util.merge_dicts(242                    defaults, util.safe_load(interpolated_config)243                )244        return defaults245    def _interpolate(self, stream, env, keep_string):246        env = set_env_from_file(env, self.env_file)247        i = interpolation.Interpolator(interpolation.TemplateWithDefaults, env)248        try:249            return i.interpolate(stream, keep_string)250        except interpolation.InvalidInterpolation as e:251            msg = "parsing config file '{}'.\n\n" "{}\n{}".format(252                self.molecule_file, e.place, e.string253            )254            util.sysexit_with_message(msg)255    def _get_defaults(self):256        if not self.molecule_file:257            scenario_name = "default"258        else:259            scenario_name = (260                os.path.basename(os.path.dirname(self.molecule_file)) or "default"261            )262        return {263            "dependency": {264                "name": "galaxy",265                "command": None,266                "enabled": True,267                "options": {},268                "env": {},269            },270            "driver": {271                "name": "docker",272                "provider": {"name": None},273                "options": {"managed": True},274                "ssh_connection_options": [],275                "safe_files": [],276            },277            "platforms": [],278            "provisioner": {279                "name": "ansible",280                "config_options": {},281                "ansible_args": [],282                "connection_options": {},283                "options": {},284                "env": {},285                "inventory": {286                    "hosts": {},287                    "host_vars": {},288                    "group_vars": {},289                    "links": {},290                },291                "children": {},292                "playbooks": {293                    "cleanup": "cleanup.yml",294                    "create": "create.yml",295                    "converge": "converge.yml",296                    "destroy": "destroy.yml",297                    "prepare": "prepare.yml",298                    "side_effect": "side_effect.yml",299                    "verify": "verify.yml",300                },301                "lint": {302                    "name": "ansible-lint",303                    "enabled": True,304                    "options": {},305                    "env": {},306                },307            },308            "scenario": {309                "name": scenario_name,310                "check_sequence": [311                    "dependency",312                    "cleanup",313                    "destroy",314                    "create",315                    "prepare",316                    "converge",317                    "check",318                    "cleanup",319                    "destroy",320                ],321                "cleanup_sequence": ["cleanup"],322                "converge_sequence": ["dependency", "create", "prepare", "converge"],323                "create_sequence": ["dependency", "create", "prepare"],324                "destroy_sequence": ["dependency", "cleanup", "destroy"],325                "test_sequence": [326                    # dependency must be kept before lint to avoid errors327                    "dependency",328                    "lint",329                    "cleanup",330                    "destroy",331                    "syntax",332                    "create",333                    "prepare",334                    "converge",335                    "idempotence",336                    "side_effect",337                    "verify",338                    "cleanup",339                    "destroy",340                ],341            },342            "verifier": {343                "name": "ansible",344                "enabled": True,345                "options": {},346                "env": {},347                "additional_files_or_dirs": [],348            },349        }350    def _preflight(self, data):351        env = os.environ.copy()352        env = set_env_from_file(env, self.env_file)353        errors, data = schema_v3.pre_validate(data, env, MOLECULE_KEEP_STRING)354        if errors:355            msg = "Failed to pre-validate.\n\n{}".format(errors)356            util.sysexit_with_message(msg, detail=data)357    def _validate(self):358        msg = "Validating schema {}.".format(self.molecule_file)359        LOG.debug(msg)360        errors = schema_v3.validate(self.config)361        if errors:362            msg = "Failed to validate.\n\n{}".format(errors)363            util.sysexit_with_message(msg)364        msg = "Validation completed successfully."365        LOG.debug(msg)366def molecule_directory(path):367    """Return directory of the current scenario."""368    return os.path.join(path, MOLECULE_DIRECTORY)369def molecule_file(path):370    """Return file path of current scenario."""371    return os.path.join(path, MOLECULE_FILE)372def set_env_from_file(env, env_file):373    """Load environment from file."""374    if env_file and os.path.exists(env_file):375        env = env.copy()376        d = util.safe_load_file(env_file)377        for k, v in d.items():378            env[k] = v379        return env...odsc-02.py
Source:odsc-02.py  
1import mlrun2from os import path3mlrun.set_env_from_file(".env")4project_name_base = 'odsc-2022-east'5project_name, artifact_path = mlrun.set_environment(project=project_name_base, artifact_path='./', user_project=True)6fn = mlrun.code_to_function(kind='job',7                      filename='data_iris.py',8                      handler='iris_generator',9                      image='mlrun/mlrun')10params={"format":"parquet"}11fn.run(params=params,...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
