Best Python code snippet using behave
model_core.py
Source:model_core.py
...9from behave.capture import Captured10from behave.textutil import text as _text11from enum import Enum12PLATFORM_WIN = sys.platform.startswith("win")13def posixpath_normalize(path):14 return path.replace("\\", "/")15# -----------------------------------------------------------------------------16# GENERIC MODEL CLASSES:17# -----------------------------------------------------------------------------18class Status(Enum):19 """Provides the (test-run) status of a model element.20 Features and Scenarios use: untested, skipped, passed, failed.21 Steps may use all enum-values.22 Enum values:23 * untested (initial state):24 Defines the initial state before a test-run.25 Sometimes used to indicate that the model element was not executed26 during a test run.27 * skipped:28 A model element is skipped because it should not run.29 This is caused by filtering mechanisms, like tags, active-tags,30 file-location arg, select-by-name, etc.31 * passed: A model element was executed and passed (without failures).32 * failed: Failures occurred while executing it.33 * undefined: Used for undefined-steps (no step implementation was found).34 * executing: Marks the steps during execution (used in a formatter)35 .. versionadded:: 1.2.636 Superceeds string-based status values.37 """38 untested = 039 skipped = 140 passed = 241 failed = 342 undefined = 443 executing = 544 def __eq__(self, other):45 """Comparison operator equals-to other value.46 Supports other enum-values and string (for backward compatibility).47 EXAMPLES::48 status = Status.passed49 assert status == Status.passed50 assert status == "passed"51 assert status != "failed"52 :param other: Other value to compare (enum-value, string).53 :return: True, if both values are equal. False, otherwise.54 """55 if isinstance(other, six.string_types):56 # -- CONVENIENCE: Compare with string-name (backward-compatible)57 return self.name == other58 return super(Status, self).__eq__(other)59 @classmethod60 def from_name(cls, name):61 """Select enumeration value by using its name.62 :param name: Name as key to the enum value (as string).63 :return: Enum value (instance)64 :raises: LookupError, if status name is unknown.65 """66 # pylint: disable=no-member67 enum_value = cls.__members__.get(name, None)68 if enum_value is None:69 known_names = ", ".join(cls.__members__.keys())70 raise LookupError("%s (expected: %s)" % (name, known_names))71 return enum_value72class Argument(object):73 """An argument found in a *feature file* step name and extracted using74 step decorator `parameters`_.75 The attributes are:76 .. attribute:: original77 The actual text matched in the step name.78 .. attribute:: value79 The potentially type-converted value of the argument.80 .. attribute:: name81 The name of the argument. This will be None if the parameter is82 anonymous.83 .. attribute:: start84 The start index in the step name of the argument. Used for display.85 .. attribute:: end86 The end index in the step name of the argument. Used for display.87 """88 def __init__(self, start, end, original, value, name=None):89 self.start = start90 self.end = end91 self.original = original92 self.value = value93 self.name = name94# @total_ordering95# class FileLocation(unicode):96class FileLocation(object):97 """98 Provides a value object for file location objects.99 A file location consists of:100 * filename101 * line (number), optional102 LOCATION SCHEMA:103 * "{filename}:{line}" or104 * "{filename}" (if line number is not present)105 """106 __pychecker__ = "missingattrs=line" # -- Ignore warnings for 'line'.107 def __init__(self, filename, line=None):108 if PLATFORM_WIN:109 filename = posixpath_normalize(filename)110 self.filename = filename111 self.line = line112 def get(self):113 return self.filename114 def abspath(self):115 return os.path.abspath(self.filename)116 def basename(self):117 return os.path.basename(self.filename)118 def dirname(self):119 return os.path.dirname(self.filename)120 def relpath(self, start=os.curdir):121 """Compute relative path for start to filename.122 :param start: Base path or start directory (default=current dir).123 :return: Relative path from start to filename...
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!!