Skip to content

Commit a00f2e2

Browse files
authored
Merge pull request #532 from python/main
Sync Fork from Upstream Repo
2 parents 58b9647 + 689b05c commit a00f2e2

File tree

12 files changed

+80
-75
lines changed

12 files changed

+80
-75
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Lib/ast.py @isidentical
128128

129129
**/*idlelib* @terryjreedy
130130

131-
**/*typing* @gvanrossum @ilevkivskyi
131+
**/*typing* @gvanrossum @Fidget-Spinner
132132

133133
**/*asyncore @giampaolo
134134
**/*asynchat @giampaolo

Lib/test/test_plistlib.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
import unittest
77
import plistlib
88
import os
9+
import sys
10+
import json
911
import datetime
1012
import codecs
13+
import subprocess
1114
import binascii
1215
import collections
1316
from test import support
@@ -997,6 +1000,77 @@ def test__all__(self):
9971000
not_exported = {"PlistFormat", "PLISTHEADER"}
9981001
support.check__all__(self, plistlib, not_exported=not_exported)
9991002

1003+
@unittest.skipUnless(sys.platform == "darwin", "plutil utility is for Mac os")
1004+
class TestPlutil(unittest.TestCase):
1005+
file_name = "plutil_test.plist"
1006+
properties = {
1007+
"fname" : "H",
1008+
"lname":"A",
1009+
"marks" : {"a":100, "b":0x10}
1010+
}
1011+
exptected_properties = {
1012+
"fname" : "H",
1013+
"lname": "A",
1014+
"marks" : {"a":100, "b":16}
1015+
}
1016+
pl = {
1017+
"HexType" : 0x0100000c,
1018+
"IntType" : 0o123
1019+
}
1020+
1021+
@classmethod
1022+
def setUpClass(cls) -> None:
1023+
## Generate plist file with plistlib and parse with plutil
1024+
with open(cls.file_name,'wb') as f:
1025+
plistlib.dump(cls.properties, f, fmt=plistlib.FMT_BINARY)
1026+
1027+
@classmethod
1028+
def tearDownClass(cls) -> None:
1029+
os.remove(cls.file_name)
1030+
1031+
def get_lint_status(self):
1032+
return subprocess.run(['plutil', "-lint", self.file_name], capture_output=True, text=True).stdout
1033+
1034+
def convert_to_json(self):
1035+
"""Convert binary file to json using plutil
1036+
"""
1037+
subprocess.run(['plutil', "-convert", 'json', self.file_name])
1038+
1039+
def convert_to_bin(self):
1040+
"""Convert file to binary using plutil
1041+
"""
1042+
subprocess.run(['plutil', "-convert", 'binary1', self.file_name])
1043+
1044+
def write_pl(self):
1045+
"""Write Hex properties to file using writePlist
1046+
"""
1047+
with open(self.file_name, 'wb') as f:
1048+
plistlib.dump(self.pl, f, fmt=plistlib.FMT_BINARY)
1049+
1050+
def test_lint_status(self):
1051+
# check lint status of file using plutil
1052+
self.assertEqual(f"{self.file_name}: OK\n", self.get_lint_status())
1053+
1054+
def check_content(self):
1055+
# check file content with plutil converting binary to json
1056+
self.convert_to_json()
1057+
with open(self.file_name) as f:
1058+
ff = json.loads(f.read())
1059+
self.assertEqual(ff, self.exptected_properties)
1060+
1061+
def check_plistlib_parse(self):
1062+
# Generate plist files with plutil and parse with plistlib
1063+
self.convert_to_bin()
1064+
with open(self.file_name, 'rb') as f:
1065+
self.assertEqual(plistlib.load(f), self.exptected_properties)
1066+
1067+
def test_octal_and_hex(self):
1068+
self.write_pl()
1069+
self.convert_to_json()
1070+
with open(self.file_name, 'r') as f:
1071+
p = json.loads(f.read())
1072+
self.assertEqual(p.get("HexType"), 16777228)
1073+
self.assertEqual(p.get("IntType"), 83)
10001074

10011075
if __name__ == '__main__':
10021076
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added interop tests for Apple plists: generate plist files with Python
2+
plistlib and parse with Apple plutil; and the other way round.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Removed the 'test2to3' demo project that demonstrated using lib2to3
2+
to support Python 2.x and Python 3.x from a single source in
3+
a distutils package. Patch by Dong-hee Na

Tools/README

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ scripts A number of useful single-file programs, e.g. tabnanny.py
3535
stringbench A suite of micro-benchmarks for various operations on
3636
strings (both 8-bit and unicode). (*)
3737

38-
test2to3 A demonstration of how to use 2to3 transparently in setup.py.
39-
4038
unicode Tools for generating unicodedata and codecs from unicode.org
4139
and other mapping files (by Fredrik Lundh, Marc-Andre Lemburg
4240
and Martin von Loewis).

Tools/test2to3/README

Lines changed: 0 additions & 3 deletions
This file was deleted.

Tools/test2to3/maintest.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

Tools/test2to3/setup.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

Tools/test2to3/test/runtests.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

Tools/test2to3/test/test_foo.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

Tools/test2to3/test2to3/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

Tools/test2to3/test2to3/hello.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)