Skip to content

Commit

Permalink
DOC-3787 added feedback suggestions and linter hints
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-stark-redis committed May 15, 2024
1 parent 8971209 commit a8791bf
Showing 1 changed file with 68 additions and 47 deletions.
115 changes: 68 additions & 47 deletions doctests/dt_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,25 @@
{
"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"],
},
{
"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},
},
Expand All @@ -179,24 +181,26 @@
{
"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"],
},
{
"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},
},
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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"],
Expand Down

0 comments on commit a8791bf

Please sign in to comment.