Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for Parenthesized Context Mgr #52

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/example-parencontext-normalization/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"authors": [
"brocla"
],
"files": {
"solution": [
"example_parencontext_normalization.py"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Examples of Parenthesized Context Managers. New feature in Python 3.10"""


#!/usr/bin/python3
"""convert json to jsonl"""

from argparse import ArgumentParser
import json

def main():
args = parse_args()

# Context Mgrs
with (
open(args.in_filename) as in_file,
open(args.out_filename, mode="wt") as out_file,
):
records = json.load(in_file)
for record in records:
out_file.write(json.dumps(record) + "\n")


def parse_args():
parser = ArgumentParser()
parser.add_argument("in_filename")
parser.add_argument("out_filename")
args = parser.parse_args()
return args

if __name__ == "__main__":
main()





# Examples from python docs
# https://docs.python.org/3/whatsnew/3.10.html#parenthesized-context-managers

def CtxManager(): pass
def CtxManager1(): pass
def CtxManager2(): pass
def CtxManager3(): pass

with (CtxManager() as example):
...

with (
CtxManager1(),
CtxManager2()
):
...

with (CtxManager1() as example,
CtxManager2()):
...

with (CtxManager1(),
CtxManager2() as example):
...

with (
CtxManager1() as example1,
CtxManager2() as example2
):
...
with (
CtxManager1() as example1,
CtxManager2() as example2,
CtxManager3() as example3,
):
...
11 changes: 11 additions & 0 deletions test/example-parencontext-normalization/mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"placeholder_0": "main",
"placeholder_1": "args",
"placeholder_2": "in_file",
"placeholder_3": "mode",
"placeholder_4": "out_file",
"placeholder_5": "records",
"placeholder_6": "record",
"placeholder_7": "parse_args",
"placeholder_8": "parser"
}
3 changes: 3 additions & 0 deletions test/example-parencontext-normalization/representation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": 2
}
Loading
Loading