From 41a91d2488db28dfb11867bdfbbcd8cb617bab5f Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 14 May 2024 14:30:36 +0100 Subject: [PATCH 1/6] DOC-3787 add missing code samples for JSON --- doctests/dt_json.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/doctests/dt_json.py b/doctests/dt_json.py index 5f17a00c3d..8708c40ef7 100644 --- a/doctests/dt_json.py +++ b/doctests/dt_json.py @@ -227,7 +227,7 @@ assert res7 == ["Phoebe", "Quaoar"] # REMOVE_END -# STEP_START filters +# STEP_START filter1 res8 = r.json().get( "bikes:inventory", "$..mountain_bikes[?(@.price < 3000 && @.specs.weight < 10)]", @@ -235,13 +235,25 @@ print( res8 ) # >>> [{'id': 'bike:2', 'model': 'Quaoar', 'description': "Redesigned for the 2020 model year, this bike impressed our testers and is the best all-around trail bike we've ever tested. The Shimano gear system effectively does away with an external cassette, so is super low maintenance in terms of wear and tear. All in all it's an impressive package for the price, making it very competitive.", 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, 'colors': ['black', 'white']}] +# STEP_END +# REMOVE_START +assert res8 == [{'id': 'bike:2', 'model': 'Quaoar', 'description': "Redesigned for the 2020 model year, this bike impressed our testers and is the best all-around trail bike we've ever tested. The Shimano gear system effectively does away with an external cassette, so is super low maintenance in terms of wear and tear. All in all it's an impressive package for the price, making it very competitive.", 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, 'colors': ['black', 'white']}] +# REMOVE_END + +# STEP_START filter2 # names of bikes made from an alloy res9 = r.json().get( "bikes:inventory", "$..[?(@.specs.material == 'alloy')].model" ) -print(res9) # >>> [['Weywot', 'Mimas']] +print(res9) # >>> ['Weywot', 'Mimas'] +# STEP_END +# REMOVE_START +assert res9 == ['Weywot', 'Mimas'] +# REMOVE_END + +# STEP_START filter3 res10 = r.json().get( "bikes:inventory", "$..[?(@.specs.material =~ '(?i)al')].model" ) @@ -252,6 +264,19 @@ assert res10 == ["Quaoar", "Weywot", "Salacia", "Mimas"] # REMOVE_END +# STEP_START filter4 +res11 = r.json().set("bikes:inventory", "$.inventory.mountain_bikes[0].regex_pat", "(?i)al") +res12 = r.json().set("bikes:inventory", "$.inventory.mountain_bikes[1].regex_pat", "(?i)al") +res13 = r.json().set("bikes:inventory", "$.inventory.mountain_bikes[2].regex_pat", "(?i)al") + +res14 = r.json().get("bikes:inventory", "$.inventory.mountain_bikes[?(@.specs.material =~ @.regex_pat)].model") +print(res14) # >>> ['Quaoar', 'Weywot'] +# STEP_END + +# REMOVE_START +assert res14 == ['Quaoar', 'Weywot'] +# REMOVE_END + # STEP_START update_bikes res11 = r.json().get("bikes:inventory", "$..price") print(res11) # >>> [1920, 2072, 3264, 1475, 3941] @@ -267,7 +292,17 @@ assert res12 == [1820, 1972, 3164, 1375, 3841] # REMOVE_END -# STEP_START update_filters +# STEP_START update_filters1 +res16 = r.json().set("bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500) +res17 = r.json().get("bikes:inventory", "$..price") +print(res17) # >>> [1500, 2072, 3264, 1500, 3941] +# STEP_END + +# REMOVE_START +assert res17 == [1500, 2072, 3264, 1500, 3941] +# REMOVE_END + +# STEP_START update_filters2 res14 = r.json().arrappend( "bikes:inventory", "$.inventory.*[?(@.price<2000)].colors", "pink" ) From 8971209f0acf6de83b8874d4ed66d9429a2149ff Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 14 May 2024 15:40:57 +0100 Subject: [PATCH 2/6] DOC-3787 applied lint checks --- doctests/dt_json.py | 53 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/doctests/dt_json.py b/doctests/dt_json.py index 8708c40ef7..2127251bae 100644 --- a/doctests/dt_json.py +++ b/doctests/dt_json.py @@ -1,5 +1,8 @@ # EXAMPLE: json_tutorial # HIDE_START +""" +Code samples for JSON doc pages: https://redis.io/docs/latest/develop/data-types/json/ +""" import redis r = redis.Redis(decode_responses=True) @@ -139,7 +142,11 @@ { "id": "bike:1", "model": "Phoebe", - "description": "This is a mid-travel trail slayer that is a fantastic daily driver or one bike quiver. The Shimano Claris 8-speed groupset gives plenty of gear range to tackle hills and there\u2019s room for mudguards and a rack too. This is the bike for the rider who wants trail manners with low fuss ownership.", + "description": "This is a mid-travel trail slayer that is a fantastic " + "daily driver or one bike quiver. The Shimano Claris 8-speed groupset " + "gives plenty of gear range to tackle hills and there\u2019s room for " + "mudguards and a rack too. This is the bike for the rider who wants " + "trail manners with low fuss ownership.", "price": 1920, "specs": {"material": "carbon", "weight": 13.1}, "colors": ["black", "silver"], @@ -147,7 +154,11 @@ { "id": "bike:2", "model": "Quaoar", - "description": "Redesigned for the 2020 model year, this bike impressed our testers and is the best all-around trail bike we've ever tested. The Shimano gear system effectively does away with an external cassette, so is super low maintenance in terms of wear and tear. All in all it's an impressive package for the price, making it very competitive.", + "description": "Redesigned for the 2020 model year, this bike impressed " + "our testers and is the best all-around trail bike we've ever tested. The " + "Shimano gear system effectively does away with an external cassette, so " + "is super low maintenance in terms of wear and tear. All in all it's an " + "impressive package for the price, making it very competitive.", "price": 2072, "specs": {"material": "aluminium", "weight": 7.9}, "colors": ["black", "white"], @@ -155,7 +166,11 @@ { "id": "bike:3", "model": "Weywot", - "description": "This bike gives kids aged six years and older a durable and uberlight mountain bike for their first experience on tracks and easy cruising through forests and fields. A set of powerful Shimano hydraulic disc brakes provide ample stopping ability. If you're after a budget option, this is one of the best bikes you could get.", + "description": "This bike gives kids aged six years and older a durable " + "and uberlight mountain bike for their first experience on tracks and easy " + "cruising through forests and fields. A set of powerful Shimano hydraulic " + "disc brakes provide ample stopping ability. If you're after a budget option, " + "this is one of the best bikes you could get.", "price": 3264, "specs": {"material": "alloy", "weight": 13.8}, }, @@ -164,7 +179,10 @@ { "id": "bike:4", "model": "Salacia", - "description": "This bike is a great option for anyone who just wants a bike to get about on With a slick-shifting Claris gears from Shimano\u2019s, this is a bike which doesn\u2019t break the bank and delivers craved performance. It\u2019s for the rider who wants both efficiency and capability.", + "description": "This bike is a great option for anyone who just wants a " + "bike to get about on With a slick-shifting Claris gears from Shimano\u2019s, " + "this is a bike which doesn\u2019t break the bank and delivers craved " + "performance. It\u2019s for the rider who wants both efficiency and capability.", "price": 1475, "specs": {"material": "aluminium", "weight": 16.6}, "colors": ["black", "silver"], @@ -172,7 +190,13 @@ { "id": "bike:5", "model": "Mimas", - "description": "A real joy to ride, this bike got very high scores in last years Bike of the year report. The carefully crafted 50-34 tooth chainset and 11-32 tooth cassette give an easy-on-the-legs bottom gear for climbing, and the high-quality Vittoria Zaffiro tires give balance and grip.It includes a low-step frame , our memory foam seat, bump-resistant shocks and conveniently placed thumb throttle. Put it all together and you get a bike that helps redefine what can be done for this price.", + "description": "A real joy to ride, this bike got very high scores in last " + "years Bike of the year report. The carefully crafted 50-34 tooth chainset " + "and 11-32 tooth cassette give an easy-on-the-legs bottom gear for climbing, " + "and the high-quality Vittoria Zaffiro tires give balance and grip.It includes " + "a low-step frame , our memory foam seat, bump-resistant shocks and " + "conveniently placed thumb throttle. Put it all together and you get a bike " + "that helps redefine what can be done for this price.", "price": 3941, "specs": {"material": "alloy", "weight": 11.6}, }, @@ -189,7 +213,8 @@ res2 = r.json().get("bikes:inventory", "$.inventory.*") print( res2 -) # >>> [[{'id': 'bike:1', 'model': 'Phoebe', 'description': 'This is a mid-travel trail slayer that is a fantastic daily driver or one bike quiver. The Shimano Claris 8-speed groupset gives plenty of gear range to tackle hills and there’s room for mudguards and a rack too. This is the bike for the rider who wants trail manners with low fuss ownership.', 'price': 1920, 'specs': {'material': 'carbon', 'weight': 13.1}, 'colors': ['black', 'silver']}, {'id': 'bike:2', 'model': 'Quaoar', 'description': "Redesigned for the 2020 model year, this bike impressed our testers and is the best all-around trail bike we've ever tested. The Shimano gear system effectively does away with an external cassette, so is super low maintenance in terms of wear and tear. All in all it's an impressive package for the price, making it very competitive.", 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, 'colors': ['black', 'white']}, {'id': 'bike:3', 'model': 'Weywot', 'description': "This bike gives kids aged six years and older a durable and uberlight mountain bike for their first experience on tracks and easy cruising through forests and fields. A set of powerful Shimano hydraulic disc brakes provide ample stopping ability. If you're after a budget option, this is one of the best bikes you could get.", 'price': 3264, 'specs': {'material': 'alloy', 'weight': 13.8}}], [{'id': 'bike:4', 'model': 'Salacia', 'description': 'This bike is a great option for anyone who just wants a bike to get about on With a slick-shifting Claris gears from Shimano’s, this is a bike which doesn’t break the bank and delivers craved performance. It’s for the rider who wants both efficiency and capability.', 'price': 1475, 'specs': {'material': 'aluminium', 'weight': 16.6}, 'colors': ['black', 'silver']}, {'id': 'bike:5', 'model': 'Mimas', 'description': 'A real joy to ride, this bike got very high scores in last years Bike of the year report. The carefully crafted 50-34 tooth chainset and 11-32 tooth cassette give an easy-on-the-legs bottom gear for climbing, and the high-quality Vittoria Zaffiro tires give balance and grip.It includes a low-step frame , our memory foam seat, bump-resistant shocks and conveniently placed thumb throttle. Put it all together and you get a bike that helps redefine what can be done for this price.', 'price': 3941, 'specs': {'material': 'alloy', 'weight': 11.6}}]] +) +# >>> [[{'id': 'bike:1', 'model': 'Phoebe', 'description': 'This is a mid-travel trail slayer... # STEP_END # STEP_START get_mtnbikes @@ -234,11 +259,18 @@ ) print( res8 -) # >>> [{'id': 'bike:2', 'model': 'Quaoar', 'description': "Redesigned for the 2020 model year, this bike impressed our testers and is the best all-around trail bike we've ever tested. The Shimano gear system effectively does away with an external cassette, so is super low maintenance in terms of wear and tear. All in all it's an impressive package for the price, making it very competitive.", 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, 'colors': ['black', 'white']}] +) # >>> [{'id': 'bike:2', 'model': 'Quaoar', 'description': "Redesigned for the 2020 model year... # STEP_END # REMOVE_START -assert res8 == [{'id': 'bike:2', 'model': 'Quaoar', 'description': "Redesigned for the 2020 model year, this bike impressed our testers and is the best all-around trail bike we've ever tested. The Shimano gear system effectively does away with an external cassette, so is super low maintenance in terms of wear and tear. All in all it's an impressive package for the price, making it very competitive.", 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, 'colors': ['black', 'white']}] +assert res8 == [{ + 'id': 'bike:2', 'model': 'Quaoar', + 'description': "Redesigned for the 2020 model year, this bike impressed our testers " + "and is the best all-around trail bike we've ever tested. The Shimano gear system " + "effectively does away with an external cassette, so is super low maintenance in terms " + "of wear and tear. All in all it's an impressive package for the price, making it very " + "competitive.", + 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, 'colors': ['black', 'white']}] # REMOVE_END # STEP_START filter2 @@ -269,7 +301,10 @@ res12 = r.json().set("bikes:inventory", "$.inventory.mountain_bikes[1].regex_pat", "(?i)al") res13 = r.json().set("bikes:inventory", "$.inventory.mountain_bikes[2].regex_pat", "(?i)al") -res14 = r.json().get("bikes:inventory", "$.inventory.mountain_bikes[?(@.specs.material =~ @.regex_pat)].model") +res14 = r.json().get( + "bikes:inventory", + "$.inventory.mountain_bikes[?(@.specs.material =~ @.regex_pat)].model" +) print(res14) # >>> ['Quaoar', 'Weywot'] # STEP_END From a8791bfd3f3d42047bfe43987553d46b4cc176e5 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Wed, 15 May 2024 11:44:01 +0100 Subject: [PATCH 3/6] DOC-3787 added feedback suggestions and linter hints --- doctests/dt_json.py | 115 ++++++++++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 47 deletions(-) diff --git a/doctests/dt_json.py b/doctests/dt_json.py index 2127251bae..575c6ecc6e 100644 --- a/doctests/dt_json.py +++ b/doctests/dt_json.py @@ -154,11 +154,12 @@ { "id": "bike:2", "model": "Quaoar", - "description": "Redesigned for the 2020 model year, this bike impressed " - "our testers and is the best all-around trail bike we've ever tested. The " - "Shimano gear system effectively does away with an external cassette, so " - "is super low maintenance in terms of wear and tear. All in all it's an " - "impressive package for the price, making it very competitive.", + "description": "Redesigned for the 2020 model year, this bike " + "impressed our testers and is the best all-around trail bike we've " + "ever tested. The Shimano gear system effectively does away with an " + "external cassette, so is super low maintenance in terms of wear " + "and tear. All in all it's an impressive package for the price, " + "making it very competitive.", "price": 2072, "specs": {"material": "aluminium", "weight": 7.9}, "colors": ["black", "white"], @@ -166,11 +167,12 @@ { "id": "bike:3", "model": "Weywot", - "description": "This bike gives kids aged six years and older a durable " - "and uberlight mountain bike for their first experience on tracks and easy " - "cruising through forests and fields. A set of powerful Shimano hydraulic " - "disc brakes provide ample stopping ability. If you're after a budget option, " - "this is one of the best bikes you could get.", + "description": "This bike gives kids aged six years and older " + "a durable and uberlight mountain bike for their first experience " + "on tracks and easy cruising through forests and fields. A set of " + "powerful Shimano hydraulic disc brakes provide ample stopping " + "ability. If you're after a budget option, this is one of the best " + "bikes you could get.", "price": 3264, "specs": {"material": "alloy", "weight": 13.8}, }, @@ -179,10 +181,11 @@ { "id": "bike:4", "model": "Salacia", - "description": "This bike is a great option for anyone who just wants a " - "bike to get about on With a slick-shifting Claris gears from Shimano\u2019s, " - "this is a bike which doesn\u2019t break the bank and delivers craved " - "performance. It\u2019s for the rider who wants both efficiency and capability.", + "description": "This bike is a great option for anyone who just " + "wants a bike to get about on With a slick-shifting Claris gears " + "from Shimano\u2019s, this is a bike which doesn\u2019t break the " + "bank and delivers craved performance. It\u2019s for the rider " + "who wants both efficiency and capability.", "price": 1475, "specs": {"material": "aluminium", "weight": 16.6}, "colors": ["black", "silver"], @@ -190,13 +193,14 @@ { "id": "bike:5", "model": "Mimas", - "description": "A real joy to ride, this bike got very high scores in last " - "years Bike of the year report. The carefully crafted 50-34 tooth chainset " - "and 11-32 tooth cassette give an easy-on-the-legs bottom gear for climbing, " - "and the high-quality Vittoria Zaffiro tires give balance and grip.It includes " + "description": "A real joy to ride, this bike got very high " + "scores in last years Bike of the year report. The carefully " + "crafted 50-34 tooth chainset and 11-32 tooth cassette give an " + "easy-on-the-legs bottom gear for climbing, and the high-quality " + "Vittoria Zaffiro tires give balance and grip.It includes " "a low-step frame , our memory foam seat, bump-resistant shocks and " - "conveniently placed thumb throttle. Put it all together and you get a bike " - "that helps redefine what can be done for this price.", + "conveniently placed thumb throttle. Put it all together and you " + "get a bike that helps redefine what can be done for this price.", "price": 3941, "specs": {"material": "alloy", "weight": 11.6}, }, @@ -214,7 +218,8 @@ print( res2 ) -# >>> [[{'id': 'bike:1', 'model': 'Phoebe', 'description': 'This is a mid-travel trail slayer... +# >>> [[{'id': 'bike:1', 'model': 'Phoebe', +# >>> 'description': 'This is a mid-travel trail slayer... # STEP_END # STEP_START get_mtnbikes @@ -259,18 +264,20 @@ ) print( res8 -) # >>> [{'id': 'bike:2', 'model': 'Quaoar', 'description': "Redesigned for the 2020 model year... +) # >>> [{'id': 'bike:2', 'model': 'Quaoar', +# 'description': "Redesigned for the 2020 model year... # STEP_END # REMOVE_START assert res8 == [{ 'id': 'bike:2', 'model': 'Quaoar', - 'description': "Redesigned for the 2020 model year, this bike impressed our testers " - "and is the best all-around trail bike we've ever tested. The Shimano gear system " - "effectively does away with an external cassette, so is super low maintenance in terms " - "of wear and tear. All in all it's an impressive package for the price, making it very " - "competitive.", - 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, 'colors': ['black', 'white']}] + 'description': "Redesigned for the 2020 model year, this bike impressed " + "our testers and is the best all-around trail bike we've ever tested. " + "The Shimano gear system effectively does away with an external cassette, " + "so is super low maintenance in terms of wear and tear. All in all it's " + "an impressive package for the price, making it very competitive.", + 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, + 'colors': ['black', 'white']}] # REMOVE_END # STEP_START filter2 @@ -297,9 +304,21 @@ # REMOVE_END # STEP_START filter4 -res11 = r.json().set("bikes:inventory", "$.inventory.mountain_bikes[0].regex_pat", "(?i)al") -res12 = r.json().set("bikes:inventory", "$.inventory.mountain_bikes[1].regex_pat", "(?i)al") -res13 = r.json().set("bikes:inventory", "$.inventory.mountain_bikes[2].regex_pat", "(?i)al") +res11 = r.json().set( + "bikes:inventory", + "$.inventory.mountain_bikes[0].regex_pat", + "(?i)al" +) +res12 = r.json().set( + "bikes:inventory", + "$.inventory.mountain_bikes[1].regex_pat", + "(?i)al" +) +res13 = r.json().set( + "bikes:inventory", + "$.inventory.mountain_bikes[2].regex_pat", + "(?i)al" +) res14 = r.json().get( "bikes:inventory", @@ -313,44 +332,46 @@ # REMOVE_END # STEP_START update_bikes -res11 = r.json().get("bikes:inventory", "$..price") -print(res11) # >>> [1920, 2072, 3264, 1475, 3941] +res15 = r.json().get("bikes:inventory", "$..price") +print(res15) # >>> [1920, 2072, 3264, 1475, 3941] -res12 = r.json().numincrby("bikes:inventory", "$..price", -100) -print(res12) # >>> [1820, 1972, 3164, 1375, 3841] +res16 = r.json().numincrby("bikes:inventory", "$..price", -100) +print(res16) # >>> [1820, 1972, 3164, 1375, 3841] -res13 = r.json().numincrby("bikes:inventory", "$..price", 100) -print(res13) # >>> [1920, 2072, 3264, 1475, 3941] +res17 = r.json().numincrby("bikes:inventory", "$..price", 100) +print(res17) # >>> [1920, 2072, 3264, 1475, 3941] # STEP_END # REMOVE_START -assert res12 == [1820, 1972, 3164, 1375, 3841] +assert res15 == [1920, 2072, 3264, 1475, 3941] +assert res16 == [1820, 1972, 3164, 1375, 3841] +assert res17 == [1920, 2072, 3264, 1475, 3941] # REMOVE_END # STEP_START update_filters1 -res16 = r.json().set("bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500) -res17 = r.json().get("bikes:inventory", "$..price") -print(res17) # >>> [1500, 2072, 3264, 1500, 3941] +res18 = r.json().set("bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500) +res19 = r.json().get("bikes:inventory", "$..price") +print(res19) # >>> [1500, 2072, 3264, 1500, 3941] # STEP_END # REMOVE_START -assert res17 == [1500, 2072, 3264, 1500, 3941] +assert res19 == [1500, 2072, 3264, 1500, 3941] # REMOVE_END # STEP_START update_filters2 -res14 = r.json().arrappend( +res20 = r.json().arrappend( "bikes:inventory", "$.inventory.*[?(@.price<2000)].colors", "pink" ) -print(res14) # >>> [3, 3] +print(res20) # >>> [3, 3] -res15 = r.json().get("bikes:inventory", "$..[*].colors") +res21 = r.json().get("bikes:inventory", "$..[*].colors") print( - res15 + res21 ) # >>> [['black', 'silver', 'pink'], ['black', 'white'], ['black', 'silver', 'pink']] # STEP_END # REMOVE_START -assert res15 == [ +assert res21 == [ ["black", "silver", "pink"], ["black", "white"], ["black", "silver", "pink"], From 5b111116b57311b68fd7ef1c2552b9c6aafdce91 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Wed, 15 May 2024 13:05:34 +0100 Subject: [PATCH 4/6] DOC-3787 added flake8 formatting --- doctests/dt_json.py | 52 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/doctests/dt_json.py b/doctests/dt_json.py index 575c6ecc6e..8e8e011b01 100644 --- a/doctests/dt_json.py +++ b/doctests/dt_json.py @@ -215,9 +215,7 @@ # STEP_START get_bikes res2 = r.json().get("bikes:inventory", "$.inventory.*") -print( - res2 -) +print(res2) # >>> [[{'id': 'bike:1', 'model': 'Phoebe', # >>> 'description': 'This is a mid-travel trail slayer... # STEP_END @@ -262,22 +260,26 @@ "bikes:inventory", "$..mountain_bikes[?(@.price < 3000 && @.specs.weight < 10)]", ) -print( - res8 -) # >>> [{'id': 'bike:2', 'model': 'Quaoar', +print(res8) +# >>> [{'id': 'bike:2', 'model': 'Quaoar', # 'description': "Redesigned for the 2020 model year... # STEP_END # REMOVE_START -assert res8 == [{ - 'id': 'bike:2', 'model': 'Quaoar', - 'description': "Redesigned for the 2020 model year, this bike impressed " - "our testers and is the best all-around trail bike we've ever tested. " - "The Shimano gear system effectively does away with an external cassette, " - "so is super low maintenance in terms of wear and tear. All in all it's " - "an impressive package for the price, making it very competitive.", - 'price': 2072, 'specs': {'material': 'aluminium', 'weight': 7.9}, - 'colors': ['black', 'white']}] +assert res8 == [ + { + 'id': 'bike:2', + 'model': 'Quaoar', + 'description': "Redesigned for the 2020 model year, this bike impressed " + "our testers and is the best all-around trail bike we've ever tested. " + "The Shimano gear system effectively does away with an external cassette, " + "so is super low maintenance in terms of wear and tear. All in all it's " + "an impressive package for the price, making it very competitive.", + 'price': 2072, + 'specs': {'material': 'aluminium', 'weight': 7.9}, + 'colors': ['black', 'white'] + } +] # REMOVE_END # STEP_START filter2 @@ -289,7 +291,7 @@ # STEP_END # REMOVE_START -assert res9 == ['Weywot', 'Mimas'] +assert res9 == ["Weywot", "Mimas"] # REMOVE_END # STEP_START filter3 @@ -305,19 +307,13 @@ # STEP_START filter4 res11 = r.json().set( - "bikes:inventory", - "$.inventory.mountain_bikes[0].regex_pat", - "(?i)al" + "bikes:inventory", "$.inventory.mountain_bikes[0].regex_pat", "(?i)al" ) res12 = r.json().set( - "bikes:inventory", - "$.inventory.mountain_bikes[1].regex_pat", - "(?i)al" + "bikes:inventory", "$.inventory.mountain_bikes[1].regex_pat", "(?i)al" ) res13 = r.json().set( - "bikes:inventory", - "$.inventory.mountain_bikes[2].regex_pat", - "(?i)al" + "bikes:inventory", "$.inventory.mountain_bikes[2].regex_pat", "(?i)al" ) res14 = r.json().get( @@ -328,7 +324,7 @@ # STEP_END # REMOVE_START -assert res14 == ['Quaoar', 'Weywot'] +assert res14 == ["Quaoar", "Weywot"] # REMOVE_END # STEP_START update_bikes @@ -349,7 +345,9 @@ # REMOVE_END # STEP_START update_filters1 -res18 = r.json().set("bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500) +res18 = r.json().set( + "bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500 +) res19 = r.json().get("bikes:inventory", "$..price") print(res19) # >>> [1500, 2072, 3264, 1500, 3941] # STEP_END From e6a3e1c3c8d26bf0d0ab856ba4dff3e253306c64 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Wed, 15 May 2024 13:17:00 +0100 Subject: [PATCH 5/6] DOC-3787 applied black formatting --- doctests/dt_json.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/doctests/dt_json.py b/doctests/dt_json.py index 8e8e011b01..fd58997c3b 100644 --- a/doctests/dt_json.py +++ b/doctests/dt_json.py @@ -268,25 +268,23 @@ # REMOVE_START assert res8 == [ { - 'id': 'bike:2', - 'model': 'Quaoar', - 'description': "Redesigned for the 2020 model year, this bike impressed " + "id": "bike:2", + "model": "Quaoar", + "description": "Redesigned for the 2020 model year, this bike impressed " "our testers and is the best all-around trail bike we've ever tested. " "The Shimano gear system effectively does away with an external cassette, " "so is super low maintenance in terms of wear and tear. All in all it's " "an impressive package for the price, making it very competitive.", - 'price': 2072, - 'specs': {'material': 'aluminium', 'weight': 7.9}, - 'colors': ['black', 'white'] + "price": 2072, + "specs": {"material": "aluminium", "weight": 7.9}, + "colors": ["black", "white"], } ] # REMOVE_END # STEP_START filter2 # names of bikes made from an alloy -res9 = r.json().get( - "bikes:inventory", "$..[?(@.specs.material == 'alloy')].model" -) +res9 = r.json().get("bikes:inventory", "$..[?(@.specs.material == 'alloy')].model") print(res9) # >>> ['Weywot', 'Mimas'] # STEP_END @@ -295,9 +293,7 @@ # REMOVE_END # STEP_START filter3 -res10 = r.json().get( - "bikes:inventory", "$..[?(@.specs.material =~ '(?i)al')].model" -) +res10 = r.json().get("bikes:inventory", "$..[?(@.specs.material =~ '(?i)al')].model") print(res10) # >>> ['Quaoar', 'Weywot', 'Salacia', 'Mimas'] # STEP_END @@ -318,9 +314,9 @@ res14 = r.json().get( "bikes:inventory", - "$.inventory.mountain_bikes[?(@.specs.material =~ @.regex_pat)].model" + "$.inventory.mountain_bikes[?(@.specs.material =~ @.regex_pat)].model", ) -print(res14) # >>> ['Quaoar', 'Weywot'] +print(res14) # >>> ['Quaoar', 'Weywot'] # STEP_END # REMOVE_START @@ -345,11 +341,9 @@ # REMOVE_END # STEP_START update_filters1 -res18 = r.json().set( - "bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500 -) +res18 = r.json().set("bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500) res19 = r.json().get("bikes:inventory", "$..price") -print(res19) # >>> [1500, 2072, 3264, 1500, 3941] +print(res19) # >>> [1500, 2072, 3264, 1500, 3941] # STEP_END # REMOVE_START From 55cb1003ad82ff80f8a52b76ec2f41f9cc2e328f Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Wed, 15 May 2024 13:24:40 +0100 Subject: [PATCH 6/6] DOC-3787 lint reformatting --- doctests/dt_json.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/doctests/dt_json.py b/doctests/dt_json.py index fd58997c3b..152b61fb10 100644 --- a/doctests/dt_json.py +++ b/doctests/dt_json.py @@ -284,7 +284,9 @@ # STEP_START filter2 # names of bikes made from an alloy -res9 = r.json().get("bikes:inventory", "$..[?(@.specs.material == 'alloy')].model") +res9 = r.json().get( + "bikes:inventory", "$..[?(@.specs.material == 'alloy')].model" +) print(res9) # >>> ['Weywot', 'Mimas'] # STEP_END @@ -293,7 +295,9 @@ # REMOVE_END # STEP_START filter3 -res10 = r.json().get("bikes:inventory", "$..[?(@.specs.material =~ '(?i)al')].model") +res10 = r.json().get( + "bikes:inventory", "$..[?(@.specs.material =~ '(?i)al')].model" +) print(res10) # >>> ['Quaoar', 'Weywot', 'Salacia', 'Mimas'] # STEP_END @@ -341,7 +345,9 @@ # REMOVE_END # STEP_START update_filters1 -res18 = r.json().set("bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500) +res18 = r.json().set( + "bikes:inventory", "$.inventory.*[?(@.price<2000)].price", 1500 +) res19 = r.json().get("bikes:inventory", "$..price") print(res19) # >>> [1500, 2072, 3264, 1500, 3941] # STEP_END