Best Python code snippet using lemoncheesecake
test_device_tracker.py
Source:test_device_tracker.py  
1"""Test mobile app device tracker."""2async def test_sending_location(hass, create_registrations, webhook_client):3    """Test sending a location via a webhook."""4    resp = await webhook_client.post(5        "/api/webhook/{}".format(create_registrations[1]["webhook_id"]),6        json={7            "type": "update_location",8            "data": {9                "gps": [10, 20],10                "gps_accuracy": 30,11                "battery": 40,12                "altitude": 50,13                "course": 60,14                "speed": 70,15                "vertical_accuracy": 80,16                "location_name": "bar",17            },18        },19    )20    assert resp.status == 20021    await hass.async_block_till_done()22    state = hass.states.get("device_tracker.test_1_2")23    assert state is not None24    assert state.name == "Test 1"25    assert state.state == "bar"26    assert state.attributes["source_type"] == "gps"27    assert state.attributes["latitude"] == 1028    assert state.attributes["longitude"] == 2029    assert state.attributes["gps_accuracy"] == 3030    assert state.attributes["battery_level"] == 4031    assert state.attributes["altitude"] == 5032    assert state.attributes["course"] == 6033    assert state.attributes["speed"] == 7034    assert state.attributes["vertical_accuracy"] == 8035    resp = await webhook_client.post(36        "/api/webhook/{}".format(create_registrations[1]["webhook_id"]),37        json={38            "type": "update_location",39            "data": {40                "gps": [1, 2],41                "gps_accuracy": 3,42                "battery": 4,43                "altitude": 5,44                "course": 6,45                "speed": 7,46                "vertical_accuracy": 8,47            },48        },49    )50    assert resp.status == 20051    await hass.async_block_till_done()52    state = hass.states.get("device_tracker.test_1_2")53    assert state is not None54    assert state.state == "not_home"55    assert state.attributes["source_type"] == "gps"56    assert state.attributes["latitude"] == 157    assert state.attributes["longitude"] == 258    assert state.attributes["gps_accuracy"] == 359    assert state.attributes["battery_level"] == 460    assert state.attributes["altitude"] == 561    assert state.attributes["course"] == 662    assert state.attributes["speed"] == 763    assert state.attributes["vertical_accuracy"] == 864async def test_restoring_location(hass, create_registrations, webhook_client):65    """Test sending a location via a webhook."""66    resp = await webhook_client.post(67        "/api/webhook/{}".format(create_registrations[1]["webhook_id"]),68        json={69            "type": "update_location",70            "data": {71                "gps": [10, 20],72                "gps_accuracy": 30,73                "battery": 40,74                "altitude": 50,75                "course": 60,76                "speed": 70,77                "vertical_accuracy": 80,78                "location_name": "bar",79            },80        },81    )82    assert resp.status == 20083    await hass.async_block_till_done()84    state_1 = hass.states.get("device_tracker.test_1_2")85    assert state_1 is not None86    config_entry = hass.config_entries.async_entries("mobile_app")[1]87    # mobile app doesn't support unloading, so we just reload device tracker88    await hass.config_entries.async_forward_entry_unload(config_entry, "device_tracker")89    await hass.config_entries.async_forward_entry_setup(config_entry, "device_tracker")90    await hass.async_block_till_done()91    state_2 = hass.states.get("device_tracker.test_1_2")92    assert state_2 is not None93    assert state_1 is not state_294    assert state_2.name == "Test 1"95    assert state_2.attributes["source_type"] == "gps"96    assert state_2.attributes["latitude"] == 1097    assert state_2.attributes["longitude"] == 2098    assert state_2.attributes["gps_accuracy"] == 3099    assert state_2.attributes["battery_level"] == 40100    assert state_2.attributes["altitude"] == 50101    assert state_2.attributes["course"] == 60102    assert state_2.attributes["speed"] == 70...Task 4.9.py
Source:Task 4.9.py  
...8#```python9# test_strings = ["hello", "world", "python", ]10# print(test_1_1(*strings))11# >>> {'o'}12# print(test_1_2(*strings))13# >>> {'d', 'e', 'h', 'l', 'n', 'o', 'p', 'r', 't', 'w', 'y'}14# print(test_1_3(*strings))15# >>> {'h', 'l', 'o'}16# print(test_1_4(*strings))17# >>> {'a', 'b', 'c', 'f', 'g', 'i', 'j', 'k', 'm', 'q', 's', 'u', 'v', 'x', 'z'}18#```19import string20############################################### ugly functions lives here )))21def all_char_in_lst(inp_str_lst: list): # forming char sets grouped by str22    all_str_lst = []23    one_word_char = []24    for i in range(len(inp_str_lst)):25        for ch in inp_str_lst[i]:26            if ch not in one_word_char:27                one_word_char.append(ch)          28        all_str_lst.append(one_word_char)29        one_word_char = []30    return all_str_lst31def let_it_dict (inp_list_for_dict: list):  # forming of a dictionary w the n of entries32    test_strings = inp_to_list(*strings)33    dict_of_char = {}34    inp_list_for_dict = test_1_2(inp_list_for_dict)35    for ch_key in inp_list_for_dict:  # fill in w zeros f further calc36        dict_of_char[ch_key] = int(0)37    for ch_key in all_char_in_lst(test_strings): # ext unique char w break by str38        for ch in ch_key:     39             if ch in dict_of_char: # running char calc entries in str 40                dict_of_char[ch] = int(str(dict_of_char[ch])) + 141    return dict_of_char42def entry_counter (test_str: list, min_entry_counter = 2 ): # default value of entr=2 for sub.task 343    out_list = []44    for key, value in let_it_dict(test_str).items():45        if value >= min_entry_counter:46            out_list.append(key)47    return out_list48def inp_to_list(*args):49    output = []50    for wrd in args:51        output.append(wrd)52    return output53###############################################54    55def test_1_1(*strings): 56    test_strings = inp_to_list(*strings)57    return entry_counter(test_strings, len(all_char_in_lst(test_strings)))58def test_1_2(*test_str): # all unique char - will use later59    if  isinstance(test_str, tuple):60        test_str = inp_to_list(*strings)61    else:62        test_str = list(test_str)63    str_of_1_wrds = []64    for i in range(len(test_str)):65        for ch in test_str[i]:66            if ch not in str_of_1_wrds:67                str_of_1_wrds.append(ch)68    str_of_1_wrds = sorted(str_of_1_wrds)69    return str_of_1_wrds70def test_1_3(*strings):71    test_strings = inp_to_list(*strings)72    return entry_counter(test_strings)    73def test_1_4(*strings): 74    test_strings = inp_to_list(*strings)75    unused_alph = []76    alph = string.ascii_lowercase77    for ch in alph:78        if ch not in (test_1_2(test_strings)):79            unused_alph.append(ch)80    unused_alph = sorted(unused_alph)81    return unused_alph82strings = ["hello", "world", "python", ]83print(test_1_1(*strings))84print(test_1_2(*strings))85print(test_1_3(*strings))...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!!
