Best Python code snippet using localstack_python
gen.py
Source:gen.py  
1# This file was automatically generated by SWIG (http://www.swig.org).2# Version 3.0.123#4# Do not make changes to this file unless you know what you are doing--modify5# the SWIG interface file instead.6from sys import version_info as _swig_python_version_info7if _swig_python_version_info >= (3, 0, 0):8    new_instancemethod = lambda func, inst, cls: _gen.SWIG_PyInstanceMethod_New(func)9else:10    from new import instancemethod as new_instancemethod11if _swig_python_version_info >= (2, 7, 0):12    def swig_import_helper():13        import importlib14        pkg = __name__.rpartition('.')[0]15        mname = '.'.join((pkg, '_gen')).lstrip('.')16        try:17            return importlib.import_module(mname)18        except ImportError:19            return importlib.import_module('_gen')20    _gen = swig_import_helper()21    del swig_import_helper22elif _swig_python_version_info >= (2, 6, 0):23    def swig_import_helper():24        from os.path import dirname25        import imp26        fp = None27        try:28            fp, pathname, description = imp.find_module('_gen', [dirname(__file__)])29        except ImportError:30            import _gen31            return _gen32        try:33            _mod = imp.load_module('_gen', fp, pathname, description)34        finally:35            if fp is not None:36                fp.close()37        return _mod38    _gen = swig_import_helper()39    del swig_import_helper40else:41    import _gen42del _swig_python_version_info43try:44    _swig_property = property45except NameError:46    pass  # Python < 2.2 doesn't have 'property'.47try:48    import builtins as __builtin__49except ImportError:50    import __builtin__51def _swig_setattr_nondynamic(self, class_type, name, value, static=1):52    if (name == "thisown"):53        return self.this.own(value)54    if (name == "this"):55        if type(value).__name__ == 'SwigPyObject':56            self.__dict__[name] = value57            return58    method = class_type.__swig_setmethods__.get(name, None)59    if method:60        return method(self, value)61    if (not static):62        object.__setattr__(self, name, value)63    else:64        raise AttributeError("You cannot add attributes to %s" % self)65def _swig_setattr(self, class_type, name, value):66    return _swig_setattr_nondynamic(self, class_type, name, value, 0)67def _swig_getattr(self, class_type, name):68    if (name == "thisown"):69        return self.this.own()70    method = class_type.__swig_getmethods__.get(name, None)71    if method:72        return method(self)73    raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))74def _swig_repr(self):75    try:76        strthis = "proxy of " + self.this.__repr__()77    except __builtin__.Exception:78        strthis = ""79    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)80def _swig_setattr_nondynamic_method(set):81    def set_attr(self, name, value):82        if (name == "thisown"):83            return self.this.own(value)84        if hasattr(self, name) or (name == "this"):85            set(self, name, value)86        else:87            raise AttributeError("You cannot add attributes to %s" % self)88    return set_attr89SHARED_PTR_DISOWN = _gen.SHARED_PTR_DISOWN90import spot.impl91AUT_BEGIN = _gen.AUT_BEGIN92AUT_KS_NCA = _gen.AUT_KS_NCA93AUT_L_NBA = _gen.AUT_L_NBA94AUT_L_DSA = _gen.AUT_L_DSA95AUT_M_NBA = _gen.AUT_M_NBA96AUT_END = _gen.AUT_END97def aut_pattern(*args) -> "spot::twa_graph_ptr":98    return _gen.aut_pattern(*args)99aut_pattern = _gen.aut_pattern100def aut_pattern_name(pattern: 'spot::gen::aut_pattern_id') -> "char const *":101    return _gen.aut_pattern_name(pattern)102aut_pattern_name = _gen.aut_pattern_name103LTL_BEGIN = _gen.LTL_BEGIN104LTL_AND_F = _gen.LTL_AND_F105LTL_AND_FG = _gen.LTL_AND_FG106LTL_AND_GF = _gen.LTL_AND_GF107LTL_CCJ_ALPHA = _gen.LTL_CCJ_ALPHA108LTL_CCJ_BETA = _gen.LTL_CCJ_BETA109LTL_CCJ_BETA_PRIME = _gen.LTL_CCJ_BETA_PRIME110LTL_DAC_PATTERNS = _gen.LTL_DAC_PATTERNS111LTL_EH_PATTERNS = _gen.LTL_EH_PATTERNS112LTL_FXG_OR = _gen.LTL_FXG_OR113LTL_GF_EQUIV = _gen.LTL_GF_EQUIV114LTL_GF_EQUIV_XN = _gen.LTL_GF_EQUIV_XN115LTL_GF_IMPLIES = _gen.LTL_GF_IMPLIES116LTL_GF_IMPLIES_XN = _gen.LTL_GF_IMPLIES_XN117LTL_GH_Q = _gen.LTL_GH_Q118LTL_GH_R = _gen.LTL_GH_R119LTL_GO_THETA = _gen.LTL_GO_THETA120LTL_GXF_AND = _gen.LTL_GXF_AND121LTL_HKRSS_PATTERNS = _gen.LTL_HKRSS_PATTERNS122LTL_KR_N = _gen.LTL_KR_N123LTL_KR_NLOGN = _gen.LTL_KR_NLOGN124LTL_KV_PSI = _gen.LTL_KV_PSI125LTL_MS_EXAMPLE = _gen.LTL_MS_EXAMPLE126LTL_MS_PHI_H = _gen.LTL_MS_PHI_H127LTL_MS_PHI_R = _gen.LTL_MS_PHI_R128LTL_MS_PHI_S = _gen.LTL_MS_PHI_S129LTL_OR_FG = _gen.LTL_OR_FG130LTL_OR_G = _gen.LTL_OR_G131LTL_OR_GF = _gen.LTL_OR_GF132LTL_P_PATTERNS = _gen.LTL_P_PATTERNS133LTL_PPS_ARBITER_STANDARD = _gen.LTL_PPS_ARBITER_STANDARD134LTL_PPS_ARBITER_STRICT = _gen.LTL_PPS_ARBITER_STRICT135LTL_R_LEFT = _gen.LTL_R_LEFT136LTL_R_RIGHT = _gen.LTL_R_RIGHT137LTL_RV_COUNTER = _gen.LTL_RV_COUNTER138LTL_RV_COUNTER_CARRY = _gen.LTL_RV_COUNTER_CARRY139LTL_RV_COUNTER_CARRY_LINEAR = _gen.LTL_RV_COUNTER_CARRY_LINEAR140LTL_RV_COUNTER_LINEAR = _gen.LTL_RV_COUNTER_LINEAR141LTL_SB_PATTERNS = _gen.LTL_SB_PATTERNS142LTL_SEJK_F = _gen.LTL_SEJK_F143LTL_SEJK_J = _gen.LTL_SEJK_J144LTL_SEJK_K = _gen.LTL_SEJK_K145LTL_SEJK_PATTERNS = _gen.LTL_SEJK_PATTERNS146LTL_TV_F1 = _gen.LTL_TV_F1147LTL_TV_F2 = _gen.LTL_TV_F2148LTL_TV_G1 = _gen.LTL_TV_G1149LTL_TV_G2 = _gen.LTL_TV_G2150LTL_TV_UU = _gen.LTL_TV_UU151LTL_U_LEFT = _gen.LTL_U_LEFT152LTL_U_RIGHT = _gen.LTL_U_RIGHT153LTL_END = _gen.LTL_END154def ltl_pattern(pattern: 'spot::gen::ltl_pattern_id', n: 'int', m: 'int'=-1) -> "spot::formula":155    return _gen.ltl_pattern(pattern, n, m)156ltl_pattern = _gen.ltl_pattern157def ltl_pattern_name(pattern: 'spot::gen::ltl_pattern_id') -> "char const *":158    return _gen.ltl_pattern_name(pattern)159ltl_pattern_name = _gen.ltl_pattern_name160def ltl_pattern_max(pattern: 'spot::gen::ltl_pattern_id') -> "int":161    return _gen.ltl_pattern_max(pattern)162ltl_pattern_max = _gen.ltl_pattern_max163def ltl_pattern_argc(pattern: 'spot::gen::ltl_pattern_id') -> "int":164    return _gen.ltl_pattern_argc(pattern)165ltl_pattern_argc = _gen.ltl_pattern_argc166def ltl_patterns(*args):167  """168  Generate LTL patterns.169  Each argument should specify a pattern with a170  range for its parameter(s).171  For single-parameter patterns, arguments of172  ltl_patterns() should be have one of these three forms:173    - (id, n)174    - (id, min, max)175    - id176  In the first case, the pattern id=n is generated.  In the second177  case, all pattern id=n for min<=n<=max are generated.  The178  third case is a shorthand for (id, 1, 10), except when179  id denotes one of the hard-coded list of LTL formulas (like,180  DAC_PATTERNS, EH_PATTERNS, etc.) where all formulas from that181  list are output.182  For two-parameter patterns, arguments of183  ltl_patterns() should be have one of these four forms:184    - (id, n1)185    - (id, n1, n2)186    - (id, min1, max1, min2, max2)187    - id188  In the first case, n2 is assumed to be equal to n1.  In189  the third case, all combination of n1 and n2 such that190  min1<=n1<=max1 and min2<=n2<=max2 are generated.  The191  last case is a shorthand for (id, 1, 3, 1, 3).192  """193  for spec in args:194    min2 = -1195    max2 = -1196    if type(spec) is int:197      pat = spec198      min = 1199      argc = ltl_pattern_argc(spec)200      if argc == 1:201        max = ltl_pattern_max(spec) or 10202      else:203        min2 = 1204        max = max2 = 3205    else:206      argc = ltl_pattern_argc(spec[0])207      ls = len(spec)208      if argc == 1:209        if ls == 2:210          pat, min, max = spec[0], spec[1], spec[1]211        elif ls == 3:212          pat, min, max = spec213        else:214          raise RuntimeError("invalid pattern specification " + str(spec))215      else:216        if ls == 2:217          pat, min, max, min2, max2 = \218            spec[0], spec[1], spec[1], spec[1], spec[1]219        elif ls == 3:220          pat, min, max, min2, max2 = \221            spec[0], spec[1], spec[1], spec[2], spec[2]222        elif ls == 5:223          pat, min, max, min2, max2 = spec224        else:225          raise RuntimeError("invalid pattern specification " + str(spec))226    for n in range(min, max + 1):227      for m in range(min2, max2 + 1):228        yield ltl_pattern(pat, n, m)229# Override aut_pattern now(), because %feature("shadow") does not230# seem to work correctly.  See https://github.com/swig/swig/issues/980231def aut_pattern(pattern: 'spot::gen::aut_pattern_id', n: 'int',232                dict: 'spot::bdd_dict_ptr' = None) -> "spot::twa_graph_ptr":233  return _gen.aut_pattern(pattern, n, dict or spot._bdd_dict)234def aut_patterns(*args):235  """236  Generate automata patterns.237  The arguments should be have one of these three forms:238    - (id, n)239    - (id, min, max)240    - id241  In the first case, the pattern id=n is generated.  In the second242  case, all pattern id=n for min<=n<=max are generated.  The243  third case is a shorthand for (id, 1, 10).244  """245  for spec in args:246    if type(spec) is int:247      pat = spec248      min = 1249      max = 10250    else:251      ls = len(spec)252      if ls == 2:253        pat, min, max = spec[0], spec[1], spec[1]254      elif ls == 3:255        pat, min, max = spec256      else:257        raise RuntimeError("invalid pattern specification")258    for n in range(min, max + 1):...test_diff.py
Source:test_diff.py  
1import json2from dvc.cli import main3def test_metrics_diff_simple(tmp_dir, scm, dvc, run_copy_metrics):4    def _gen(val):5        tmp_dir.gen({"m_temp.yaml": str(val)})6        run_copy_metrics("m_temp.yaml", "m.yaml", metrics=["m.yaml"])7        dvc.scm.commit(str(val))8    _gen(1)9    _gen(2)10    _gen(3)11    expected = {"m.yaml": {"": {"old": 1, "new": 3, "diff": 2}}}12    assert dvc.metrics.diff(a_rev="HEAD~2") == expected13def test_metrics_diff_yaml(tmp_dir, scm, dvc, run_copy_metrics):14    def _gen(val):15        metrics = {"a": {"b": {"c": val, "d": 1, "e": str(val)}}}16        (tmp_dir / "m_temp.yaml").dump(metrics)17        run_copy_metrics(18            "m_temp.yaml", "m.yaml", metrics=["m.yaml"], commit=str(val)19        )20    _gen(1)21    _gen(2)22    _gen(3)23    expected = {"m.yaml": {"a.b.c": {"old": 1, "new": 3, "diff": 2}}}24    assert dvc.metrics.diff(a_rev="HEAD~2") == expected25def test_metrics_diff_json(tmp_dir, scm, dvc, run_copy_metrics):26    def _gen(val):27        metrics = {"a": {"b": {"c": val, "d": 1, "e": str(val)}}}28        (tmp_dir / "m_temp.json").dump(metrics)29        run_copy_metrics(30            "m_temp.json", "m.json", metrics=["m.json"], commit=str(val)31        )32    _gen(1)33    _gen(2)34    _gen(3)35    expected = {"m.json": {"a.b.c": {"old": 1, "new": 3, "diff": 2}}}36    assert dvc.metrics.diff(a_rev="HEAD~2") == expected37def test_metrics_diff_json_unchanged(tmp_dir, scm, dvc, run_copy_metrics):38    def _gen(val):39        metrics = {"a": {"b": {"c": val, "d": 1, "e": str(val)}}}40        (tmp_dir / "m_temp.json").dump(metrics)41        run_copy_metrics(42            "m_temp.json", "m.json", metrics=["m.json"], commit=str(val)43        )44    _gen(1)45    _gen(2)46    _gen(1)47    assert dvc.metrics.diff(a_rev="HEAD~2") == {}48def test_metrics_diff_broken_json(tmp_dir, scm, dvc, run_copy_metrics):49    metrics = {"a": {"b": {"c": 1, "d": 1, "e": "3"}}}50    (tmp_dir / "m_temp.json").dump(metrics)51    run_copy_metrics(52        "m_temp.json",53        "m.json",54        metrics_no_cache=["m.json"],55        commit="add metrics",56    )57    (tmp_dir / "m.json").write_text(json.dumps(metrics) + "ma\nlformed\n")58    assert dvc.metrics.diff() == {59        "m.json": {60            "a.b.c": {"old": 1, "new": None},61            "a.b.d": {"old": 1, "new": None},62        }63    }64def test_metrics_diff_no_metrics(tmp_dir, scm, dvc):65    tmp_dir.scm_gen({"foo": "foo"}, commit="add foo")66    assert dvc.metrics.diff(a_rev="HEAD~1") == {}67def test_metrics_diff_new_metric(tmp_dir, scm, dvc, run_copy_metrics):68    metrics = {"a": {"b": {"c": 1, "d": 1, "e": "3"}}}69    (tmp_dir / "m_temp.json").dump(metrics)70    run_copy_metrics("m_temp.json", "m.json", metrics_no_cache=["m.json"])71    assert dvc.metrics.diff() == {72        "m.json": {73            "a.b.c": {"old": None, "new": 1},74            "a.b.d": {"old": None, "new": 1},75        }76    }77def test_metrics_diff_deleted_metric(tmp_dir, scm, dvc, run_copy_metrics):78    metrics = {"a": {"b": {"c": 1, "d": 1, "e": "3"}}}79    (tmp_dir / "m_temp.json").dump(metrics)80    run_copy_metrics(81        "m_temp.json",82        "m.json",83        metrics_no_cache=["m.json"],84        commit="add metrics",85    )86    (tmp_dir / "m.json").unlink()87    assert dvc.metrics.diff() == {88        "m.json": {89            "a.b.c": {"old": 1, "new": None},90            "a.b.d": {"old": 1, "new": None},91        }92    }93def test_metrics_diff_with_unchanged(tmp_dir, scm, dvc, run_copy_metrics):94    tmp_dir.gen("metrics_temp.yaml", "foo: 1\nxyz: 10")95    run_copy_metrics(96        "metrics_temp.yaml",97        "metrics.yaml",98        metrics_no_cache=["metrics.yaml"],99        commit="1",100    )101    tmp_dir.scm_gen("metrics.yaml", "foo: 2\nxyz: 10", commit="2")102    tmp_dir.scm_gen("metrics.yaml", "foo: 3\nxyz: 10", commit="3")103    assert dvc.metrics.diff(a_rev="HEAD~2", all=True) == {104        "metrics.yaml": {105            "foo": {"old": 1, "new": 3, "diff": 2},106            "xyz": {"old": 10, "new": 10, "diff": 0},107        }108    }109def test_no_commits(tmp_dir):110    from scmrepo.git import Git111    from dvc.repo import Repo112    git = Git.init(tmp_dir.fs_path)113    assert git.no_commits114    assert Repo.init().metrics.diff() == {}115def test_metrics_diff_dirty(tmp_dir, scm, dvc, run_copy_metrics):116    def _gen(val):117        tmp_dir.gen({"m_temp.yaml": str(val)})118        run_copy_metrics("m_temp.yaml", "m.yaml", metrics=["m.yaml"])119        dvc.scm.commit(str(val))120    _gen(1)121    _gen(2)122    _gen(3)123    tmp_dir.gen({"m.yaml": "4"})124    expected = {"m.yaml": {"": {"old": 3, "new": 4, "diff": 1}}}125    assert dvc.metrics.diff() == expected126def test_metrics_diff_cli(tmp_dir, scm, dvc, run_copy_metrics, caplog, capsys):127    def _gen(val):128        tmp_dir.gen({"m_temp.yaml": f"foo: {val}"})129        run_copy_metrics("m_temp.yaml", "m.yaml", metrics=["m.yaml"])130        dvc.scm.commit(str(val))131    _gen(1.23456789)132    _gen(2.34567891011)133    _gen(3.45678910111213)134    caplog.clear()135    capsys.readouterr()  # clearing the buffer136    assert main(["metrics", "diff", "HEAD~2"]) == 0137    captured = capsys.readouterr()138    assert captured.out == (139        "Path    Metric    HEAD~2    workspace    Change\n"140        "m.yaml  foo       1.23457   3.45679      2.22222\n"141    )142def test_metrics_diff_non_metrics(tmp_dir, scm, dvc):143    def _gen(val):144        tmp_dir.scm_gen({"some_file.yaml": f"foo: {val}"}, commit=str(val))145    _gen(1)146    _gen(2)147    _gen(3)148    result = dvc.metrics.diff(targets=["some_file.yaml"], a_rev="HEAD~2")149    assert result == {150        "some_file.yaml": {"foo": {"old": 1, "new": 3, "diff": 2}}...cursors.pyi
Source:cursors.pyi  
1from typing import Any, Dict, Iterable, Iterator, List, Optional, Text, Tuple, TypeVar, Union2from .connections import Connection3_Gen = Union[Tuple[Any, ...], Dict[Text, Any]]4_QueryArgs = Union[Tuple[Any, ...], List[Any], Dict[Text, Any], None]5_SelfT = TypeVar("_SelfT")6class Cursor:7    connection: Connection8    description: Tuple[Text, ...]9    rownumber: int10    rowcount: int11    arraysize: int12    messages: Any13    errorhandler: Any14    lastrowid: int15    def __init__(self, connection: Connection) -> None: ...16    def __del__(self) -> None: ...17    def close(self) -> None: ...18    def setinputsizes(self, *args) -> None: ...19    def setoutputsizes(self, *args) -> None: ...20    def nextset(self) -> Optional[bool]: ...21    def mogrify(self, query: Text, args: _QueryArgs = ...) -> str: ...22    def execute(self, query: Text, args: _QueryArgs = ...) -> int: ...23    def executemany(self, query: Text, args: Iterable[_QueryArgs]) -> Optional[int]: ...24    def callproc(self, procname: Text, args: Iterable[Any] = ...) -> Any: ...25    def fetchone(self) -> Optional[_Gen]: ...26    def fetchmany(self, size: Optional[int] = ...) -> Union[Optional[_Gen], List[_Gen]]: ...27    def fetchall(self) -> Optional[Tuple[_Gen, ...]]: ...28    def scroll(self, value: int, mode: Text = ...) -> None: ...29    def __iter__(self) -> Iterator[_Gen]: ...30    def __enter__(self: _SelfT) -> _SelfT: ...31    def __exit__(self, *exc_info: Any) -> None: ...32class DictCursor(Cursor):33    def fetchone(self) -> Optional[Dict[Text, Any]]: ...34    def fetchmany(self, size: Optional[int] = ...) -> Optional[Tuple[Dict[Text, Any], ...]]: ...35    def fetchall(self) -> Optional[Tuple[Dict[Text, Any], ...]]: ...36class DictCursorMixin:37    dict_type: Any38class SSCursor(Cursor):39    # fetchall return type is incompatible with the supertype.40    def fetchall(self) -> List[_Gen]: ...  # type: ignore41    def fetchall_unbuffered(self) -> Iterator[_Gen]: ...42    def __iter__(self) -> Iterator[_Gen]: ...43    def fetchmany(self, size: Optional[int] = ...) -> List[_Gen]: ...44    def scroll(self, value: int, mode: Text = ...) -> None: ......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!!
