Best Python code snippet using ATX
NCutil.py
Source:NCutil.py  
...166        ).absolutePathForAppBundleWithIdentifier_(bundle_id)167    if app_path:168        return NSFileManager.defaultManager().displayNameAtPath_(app_path)169    return bundle_id170def get_bundle_id(app_name):171    '''Given an app_name, get the bundle_id'''172    from AppKit import NSWorkspace173    from Foundation import NSBundle174    app_path = NSWorkspace.sharedWorkspace(175        ).fullPathForApplication_(app_name)176    if app_path:177        return NSBundle.bundleWithPath_(app_path).bundleIdentifier()178    return None179# flags are bits in a 16 bit(?) data structure180DONT_SHOW_IN_CENTER = 1 << 0181BADGE_ICONS = 1 << 1182SOUNDS = 1 << 2183BANNER_STYLE = 1 << 3184ALERT_STYLE = 1 << 4...test_bundles.py
Source:test_bundles.py  
...251    res2 = client.get("/ga4gh/drs/v1/objects/" + bundle_id)252    assert res2.status_code == 200253    rec2 = res2.json254    assert rec2["form"] == "bundle"255def test_bundle_get_no_bundle_id(client, user):256    did_list, _ = create_index(client, user)257    bundle_id = str(uuid.uuid4())258    data = get_bundle_doc(did_list, bundle_id=bundle_id)259    res1 = client.post("/bundle/", json=data, headers=user)260    assert res1.status_code == 200261    res2 = client.get("/bundle/" + "hc42397hf902-37g4hf970h23479fgh9euwh")262    assert res2.status_code == 404263def test_bundle_get_expand_false(client, user):264    did_list, rec = create_index(client, user)265    res1 = client.get("/ga4gh/drs/v1/objects/" + rec["did"])266    bundle_id = str(uuid.uuid4())267    data = get_bundle_doc(did_list, bundle_id=bundle_id)268    res1 = client.post("/bundle/", json=data, headers=user)269    assert res1.status_code == 200270    res2 = client.get("/bundle/" + bundle_id + "?expand=false")271    rec2 = res2.json272    assert res2.status_code == 200273    assert rec2["id"] == bundle_id274    assert rec2["name"] == data["name"]275    assert "bundle_data" not in rec2276def test_redirect_to_bundle_from_index(client, user):277    did_list, _ = create_index(client, user)278    bundle_id = str(uuid.uuid4())279    data = get_bundle_doc(did_list, bundle_id=bundle_id)280    res2 = client.post("/bundle/", json=data, headers=user)281    assert res2.status_code == 200282    res = client.get("/bundle/" + bundle_id)283    assert res.status_code == 200284    res3 = client.get("/index/" + bundle_id)285    assert res3.status_code == 200286def test_bundle_from_drs_endpoint(client, user):287    did_list, _ = create_index(client, user)288    bundle_id = str(uuid.uuid4())289    data = get_bundle_doc(did_list, bundle_id=bundle_id)290    res2 = client.post("/bundle/", json=data, headers=user)291    assert res2.status_code == 200292    res = client.get("/bundle/" + bundle_id)293    assert res.status_code == 200294    res3 = client.get("/ga4gh/drs/v1/objects/" + bundle_id)295    assert res3.status_code == 200296def test_get_bundle_list(client, user):297    """298    bundle1299        +-object1300    bundle2301        +-object2302    .303    .304    bundlen305        +-objectn306    """307    n_bundles = 6308    n_records = 6309    for _ in range(n_records):310        _, _ = create_index(client, user)311    n_records = 6 + n_bundles312    for _ in range(n_bundles):313        did_list, _ = create_index(client, user)314        bundle_id = str(uuid.uuid4())315        data = get_bundle_doc(did_list, bundle_id=bundle_id)316        res2 = client.post("/bundle/", json=data, headers=user)317        assert res2.status_code == 200318    res3 = client.get("/bundle/")319    assert res3.status_code == 200320    rec3 = res3.json321    assert len(rec3["records"]) == n_bundles322    # check to see bundle_data is not included323    assert "bundle_data" not in rec3["records"][0]324    res4 = client.get("/bundle/?form=object")325    assert res4.status_code == 200326    rec4 = res4.json327    assert len(rec4["records"]) == n_records328    res5 = client.get("/bundle/?form=all")329    assert res5.status_code == 200330    rec5 = res5.json331    assert len(rec5["records"]) == n_records + n_bundles332def test_multiple_bundle_data(client, user):333    """334    bundle1335        +-object1336        +-object2337        .338        .339        +-objectn340    """341    n_bundle_data = 5342    did_list = []343    for _ in range(n_bundle_data):344        did, _ = create_index(client, user)345        did_list.append(did[0])346    bundle_id = str(uuid.uuid4())347    data = get_bundle_doc(did_list, bundle_id=bundle_id)348    res2 = client.post("/bundle/", json=data, headers=user)349    assert res2.status_code == 200350    res3 = client.get("/bundle/" + bundle_id + "?expand=true")351    assert res3.status_code == 200352    rec3 = res3.json353    bundle_data = rec3["contents"]354    assert len(rec3["contents"]) == n_bundle_data355    for data in bundle_data:356        assert data["id"] in did_list357def test_bundle_delete(client, user):358    n_records = 6359    n_delete = 2360    bundle_ids = []361    for _ in range(n_records):362        did_list, _ = create_index(client, user)363        bundle_id = str(uuid.uuid4())364        bundle_ids.append(bundle_id)365        data = get_bundle_doc(did_list, bundle_id=bundle_id)366        res2 = client.post("/bundle/", json=data, headers=user)367        assert res2.status_code == 200368    res3 = client.get("/bundle/")369    assert res3.status_code == 200370    rec3 = res3.json371    assert len(rec3["records"]) == n_records372    for i in range(n_delete):373        res4 = client.delete("/bundle/" + bundle_ids[i], headers=user)374        assert res4.status_code == 200375        res5 = client.get("/bundle/" + bundle_ids[i])376        assert res5.status_code == 404377    res3 = client.get("/bundle/")378    assert res3.status_code == 200379    rec3 = res3.json380    assert len(rec3["records"]) == n_records - n_delete381def test_bundle_delete_invalid_bundle_id(client, user):382    bundle_id = "12938hd981h123hd18hd80h028"383    res = client.delete("/bundle/" + bundle_id, headers=user)384    assert res.status_code == 404385def test_bundle_delete_no_bundle_id(client, user):386    res = client.delete("/bundle/", headers=user)387    assert res.status_code == 405388def test_bundle_data_bundle_and_index(client, user):389    """390    bundle_main391        +-bundle1392            +-object1393        +-bundle2394            +-object2395        +-bundle3396            +-object3397        +-object1398        +-object2399        +-object3...jacobsalmela_NCutil.py
Source:jacobsalmela_NCutil.py  
...20def get_flags(bundle_id): '''Returns flags for bundle_id'''    conn, curs = connect_to_db()    curs.execute("SELECT flags from app_info where bundleid='%s'" % (bundle_id)) try:        flags = curs.fetchall()[0][0] except IndexError:        flags = 0    conn.close() return int(flags)21def get_show_count(bundle_id): '''Returns number of items to show in Notification Center for bundle_id'''    conn, curs = connect_to_db()    curs.execute("SELECT show_count from app_info where bundleid='%s'" % (bundle_id)) try:        flags = curs.fetchall()[0][0] except IndexError:        flags = 0    conn.close() return int(flags)22def remove_system_center(): '''Sets alert style to 'none'' for all bundle_ids starting with    _SYSTEM_CENTER_:. Not convinced this is a great idea, but there it is...'''    set_alert('none', get_matching_ids('_SYSTEM_CENTER_:%'))23def get_app_name(bundle_id): '''Get display name for app specified by bundle_id''' from AppKit import NSWorkspace from Foundation import NSFileManager    app_path = NSWorkspace.sharedWorkspace(        ).absolutePathForAppBundleWithIdentifier_(bundle_id) if app_path: return NSFileManager.defaultManager().displayNameAtPath_(app_path) return bundle_id24def get_bundle_id(app_name): '''Given an app_name, get the bundle_id''' from AppKit import NSWorkspace from Foundation import NSBundle    app_path = NSWorkspace.sharedWorkspace(        ).fullPathForApplication_(app_name) if app_path: return NSBundle.bundleWithPath_(app_path).bundleIdentifier() return None25# flags are bits in a 16 bit(?) data structureDONT_SHOW_IN_CENTER = 1 << 0BADGE_ICONS = 1 << 1SOUNDS = 1 << 2BANNER_STYLE = 1 << 3ALERT_STYLE = 1 << 4UNKNOWN_5 = 1 << 5UNKNOWN_6 = 1 << 6UNKNOWN_7 = 1 << 7UNKNOWN_8 = 1 << 8UNKNOWN_9 = 1 << 9UNKNOWN_10 = 1 << 10UNKNOWN_11 = 1 << 11SUPPRESS_NOTIFICATIONS_ON_LOCKSCREEN = 1 << 12SHOW_PREVIEWS_ALWAYS = 1 << 13SUPPRESS_MESSAGE_PREVIEWS = 1 << 14UNKNOWN_15 = 1 << 1526def error_and_exit_if_not_bundle_exists(bundle_id): '''Print an error and exit if bundle_id doesn't exist.''' if not bundleid_exists(bundle_id): print >> sys.stderr, "%s not in Notification Center" % bundle_id exit(1)27def get_alert_style(bundle_id): '''Print the alert style for bundle_id'''    error_and_exit_if_not_bundle_exists(bundle_id)    current_flags = get_flags(bundle_id) if current_flags & ALERT_STYLE: print "alerts" elif current_flags & BANNER_STYLE: print "banners" else: print "none"28def get_show_on_lock_screen(bundle_id): '''Print state of "Show notifications on lock screen"'''    error_and_exit_if_not_bundle_exists(bundle_id)    current_flags = get_flags(bundle_id) if current_flags & SUPPRESS_NOTIFICATIONS_ON_LOCKSCREEN: print 'false' else: print 'true'29def get_badge_app_icon(bundle_id): '''Print state of "Badge app icon"'''    error_and_exit_if_not_bundle_exists(bundle_id)    current_flags = get_flags(bundle_id) if current_flags & BADGE_ICONS: print 'true' else: print 'false'30def get_notification_sound(bundle_id): '''Print state of "Play sound for notifications"'''    error_and_exit_if_not_bundle_exists(bundle_id)    current_flags = get_flags(bundle_id) if current_flags & SOUNDS: print 'true' else: print 'false'31def get_show_in_notification_center(bundle_id): '''Print state of "Show in Notification Center"'''    error_and_exit_if_not_bundle_exists(bundle_id)    current_flags = get_flags(bundle_id) if current_flags & DONT_SHOW_IN_CENTER: print 'false' else:        show_count = get_show_count(bundle_id) if show_count == 1:            items = '1 recent item' else:            items = '%s recent items' % show_count print items32def get_info(bundle_id): '''Print the Notification Center settings for bundle_id'''    error_and_exit_if_not_bundle_exists(bundle_id)    current_flags = get_flags(bundle_id) if current_flags & ALERT_STYLE:        style = "Alerts" elif current_flags & BANNER_STYLE:        style = "Banners" else:        style = "None"    app_name = get_app_name(bundle_id) print "Notification Center settings for %s:" % app_name print ' %-34s %s' % (app_name + ' alert style:', style) if current_flags & SUPPRESS_NOTIFICATIONS_ON_LOCKSCREEN:        show_notifications_on_lock_screen = False print "    Show notifications on lock screen: No" else:        show_notifications_on_lock_screen = True print "    Show notifications on lock screen: Yes" if current_flags & SUPPRESS_MESSAGE_PREVIEWS: print "    Show message preview:              Off" elif ((current_flags & SHOW_PREVIEWS_ALWAYS) and show_notifications_on_lock_screen): print "    Show message preview:              Always" if current_flags & DONT_SHOW_IN_CENTER: print "    Show in Notification Center:       No" else:        show_count = get_show_count(bundle_id) if show_count == 1:            items = '1 Recent Item' else:            items = '%s Recent Items' % show_count print "    Show in Notification Center:       %s" % items if current_flags & BADGE_ICONS: print "    Badge app icon:                    Yes" else: print "    Badge app icon:                    No" if current_flags & SOUNDS: print "    Play sound for notifications:      Yes" else: print "    Play sound for notifications:      No"33def verify_value_in_allowed(label, value, allowed_values): '''Make sure our value has an allowed value''' if value not in allowed_values: print >> sys.stderr, ( "%s must be one of: %s." % (label, ', '.join(allowed_values))) exit(1)34def bundle_ids_or_error_and_exit(bundle_ids): '''Print an error and exit if bundle_ids is empty''' if not bundle_ids: print >> sys.stderr, "Must specify at least one bundle id!" exit(1)35def set_alert(style, bundle_ids): '''Set the alert style for bundle_id. If kill_nc is False, skip killing    the NotificationCenter and usernoted processes'''36 # verify this is a supported alert type    verify_value_in_allowed('Alert style', style, ['none', 'alerts', 'banners']) # exit if no bundle_ids were provided    bundle_ids_or_error_and_exit(bundle_ids) for bundle_id in bundle_ids: if not bundleid_exists(bundle_id): print >> sys.stderr, ( "WARNING: %s not in Notification Center" % bundle_id) else:            current_flags = get_flags(bundle_id) # turn off both banner and alert flags            new_flags = current_flags & ~(BANNER_STYLE | ALERT_STYLE) if style == 'alerts': # turn on alert flag                new_flags = new_flags | ALERT_STYLE elif style == 'banners': # turn on banner flag                new_flags = new_flags | BANNER_STYLE if new_flags != current_flags:                set_flags(new_flags, bundle_id)    kill_notification_center()37def set_show_on_lock_screen(value, bundle_ids): '''Set the boolean value for badging the app icon'''38 # verify this is a supported value    verify_value_in_allowed( 'Show on lock screen value', value, ['true', 'false']) # exit if no bundle_ids were provided    bundle_ids_or_error_and_exit(bundle_ids) for bundle_id in bundle_ids: if not bundleid_exists(bundle_id): print >> sys.stderr, ( "WARNING: %s not in Notification Center" % bundle_id) else:            current_flags = get_flags(bundle_id) if value == 'true':                new_flags = (                    current_flags & ~SUPPRESS_NOTIFICATIONS_ON_LOCKSCREEN) else:                new_flags = current_flags | SUPPRESS_NOTIFICATIONS_ON_LOCKSCREEN if new_flags != current_flags:                set_flags(new_flags, bundle_id)    kill_notification_center()...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!!
