Best Python code snippet using tempest_python
test_sql_session.py
Source:test_sql_session.py  
...130    session = SQLXFormsSession(**properties)131    session.save()132    return session133def _arbitrary_session_properties(**kwargs):134    def arbitrary_string(max_len=32):135        return uuid.uuid4().hex[:max_len]136    def arbitrary_date():137        return datetime(138            random.choice(range(2010, 2015)),139            random.choice(range(1, 13)),140            random.choice(range(1, 28)),141        )142    def arbitrary_bool():143        return random.choice([True, False])144    properties = {145        'connection_id': arbitrary_string(),146        'session_id': arbitrary_string(),147        'form_xmlns': arbitrary_string(),148        'start_time': arbitrary_date(),149        'modified_time': arbitrary_date(),150        'end_time': arbitrary_date(),151        'completed': arbitrary_bool(),152        'domain': arbitrary_string(),153        'user_id': arbitrary_string(),154        'app_id': arbitrary_string(),155        'submission_id': arbitrary_string(),156        'survey_incentive': arbitrary_string(),157        'session_type': random.choice(XFORMS_SESSION_TYPES),158        'workflow': arbitrary_string(20),159        'reminder_id': arbitrary_string(),160    }161    properties.update(kwargs)..._utils.py
Source:_utils.py  
1import collections2from typing import Hashable, Sequence, Tuple, TypeVar3import rlp4def sxor(s1: bytes, s2: bytes) -> bytes:5    if len(s1) != len(s2):6        raise ValueError("Cannot sxor strings of different length")7    return bytes(x ^ y for x, y in zip(s1, s2))8def roundup_16(x: int) -> int:9    """Rounds up the given value to the next multiple of 16."""10    remainder = x % 1611    if remainder != 0:12        x += 16 - remainder13    return x14def get_devp2p_cmd_id(msg: bytes) -> int:15    """Return the cmd_id for the given devp2p msg.16    The cmd_id, also known as the payload type, is always the first entry of the RLP, interpreted17    as an integer.18    """19    return rlp.decode(msg[:1], sedes=rlp.sedes.big_endian_int)20def trim_middle(arbitrary_string: str, max_length: int) -> str:21    """22    Trim down strings to max_length by cutting out the middle.23    This assumes that the most "interesting" bits are toward24    the beginning and the end.25    Adds a highly unusual 'âââ' in the middle where characters26    were stripped out, to avoid not realizing about the stripped27    info.28    """29    # candidate for moving to eth-utils, if we like it30    size = len(arbitrary_string)31    if size <= max_length:32        return arbitrary_string33    else:34        half_len, is_odd = divmod(max_length, 2)35        first_half = arbitrary_string[:half_len - 1]36        last_half_len = half_len - 2 + is_odd37        if last_half_len > 0:38            last_half = arbitrary_string[last_half_len * -1:]39        else:40            last_half = ''41        return f"{first_half}âââ{last_half}"42TValue = TypeVar('TValue', bound=Hashable)43def duplicates(elements: Sequence[TValue]) -> Tuple[TValue, ...]:44    return tuple(45        value for46        value, count in47        collections.Counter(elements).items()48        if count > 1...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!!
