Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-131178: Add tests forpickletools command-line interface#131287

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
donBarbos wants to merge6 commits intopython:main
base:main
Choose a base branch
Loading
fromdonBarbos:issue-131178-pickletools
Open
Changes from1 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
PrevPrevious commit
Refactor
  • Loading branch information
@donBarbos
donBarbos committedMay 20, 2025
commitce3683917cc3224f7fa065e77093a48c538aeebb
38 changes: 20 additions & 18 deletionsLib/test/test_pickletools.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -526,22 +526,22 @@ def setUp(self):

@staticmethod
def text_normalize(string):
"""Dedent *string* and strip it from its surrounding whitespaces.

This method is used by the other utility functions so that any
string to write or to match against can be freely indented.
"""
return textwrap.dedent(string).strip()

def set_pickle_data(self, data):
with open(self.filename, 'wb') as f:
pickle.dump(data, f)

def invoke_pickletools(self, *flags):
output = io.StringIO()
with contextlib.redirect_stdout(output):
stderr = io.StringIO()
stdout = io.StringIO()
with (
contextlib.redirect_stdout(stdout),
contextlib.redirect_stderr(stderr),
):
pickletools._main(args=[*flags, self.filename])
return self.text_normalize(output.getvalue())
self.assertEqual(stderr.getvalue(), '')
return self.text_normalize(stdout.getvalue())

def check_output(self, data, expect, *flags):
with self.subTest(data=data, flags=flags):
Expand All@@ -561,26 +561,28 @@ def test_invocation(self):
('-a', '--annotate'),
('-p="Another:"', '--preamble="Another:"'),
]
data = {"a", "b", "c" }
data = {'a', 'b', 'c' }

self.set_pickle_data(data)

for r in range(1, len(base_flags) + 1):
for choices in itertools.combinations(base_flags, r=r):
for args in itertools.product(*choices):
with self.subTest(args=args[1:]):
_ =self.invoke_pickletools(*args)
self.invoke_pickletools(*args)

def test_unknown_flag(self):
with self.assertRaises(SystemExit):
# suppress argparse error message
with contextlib.redirect_stderr(io.StringIO()):
_ = self.invoke_pickletools('--unknown')
output = io.StringIO()
with contextlib.redirect_stderr(output):
pickletools._main(args=['--unknown'])
self.assertStartsWith(output.getvalue(), 'usage: ')

def test_output_flag(self):
# test 'python -m pickletools -o/--output'
output_file = tempfile.mktemp()
self.addCleanup(os_helper.unlink, output_file)
data = ("fake_data",)
data = ('fake_data',)
expect = '''
0: \\x80 PROTO 5
2: \\x95 FRAME 15
Expand All@@ -605,7 +607,7 @@ def test_output_flag(self):

def test_memo_flag(self):
# test 'python -m pickletools -m/--memo'
data = ("fake_data",)
data = ('fake_data',)
expect = '''
0: \\x80 PROTO 5
2: \\x95 FRAME 15
Expand All@@ -621,7 +623,7 @@ def test_memo_flag(self):

def test_indentlevel_flag(self):
# test 'python -m pickletools -l/--indentlevel'
data = ("fake_data",)
data = ('fake_data',)
expect = '''
0: \\x80 PROTO 5
2: \\x95 FRAME 15
Expand All@@ -637,7 +639,7 @@ def test_indentlevel_flag(self):

def test_annotate_flag(self):
# test 'python -m pickletools -a/--annotate'
data = ("fake_data",)
data = ('fake_data',)
expect = '''
0: \\x80 PROTO 5 Protocol version indicator.
2: \\x95 FRAME 15 Indicate the beginning of a new frame.
Expand All@@ -653,7 +655,7 @@ def test_annotate_flag(self):

def test_preamble_flag(self):
# test 'python -m pickletools -p/--preamble'
data = ("fake_data",)
data = ('fake_data',)
expect = '''
Another:
0: \\x80 PROTO 5
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp