Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b3c728fd
Commit
b3c728fd
authored
Mar 16, 2011
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #11577: Improve binhex test coverage and fix ResourceWarning
parent
4e432682
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
18 deletions
+40
-18
Lib/binhex.py
Lib/binhex.py
+24
-18
Lib/test/test_binhex.py
Lib/test/test_binhex.py
+11
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/binhex.py
View file @
b3c728fd
...
...
@@ -52,14 +52,13 @@ class FInfo:
def
getfileinfo
(
name
):
finfo
=
FInfo
()
fp
=
io
.
open
(
name
,
'rb'
)
# Quick check for textfile
data
=
fp
.
read
(
512
)
if
0
not
in
data
:
finfo
.
Type
=
'TEXT'
fp
.
seek
(
0
,
2
)
dsize
=
fp
.
tell
()
fp
.
close
()
with
io
.
open
(
name
,
'rb'
)
as
fp
:
# Quick check for textfile
data
=
fp
.
read
(
512
)
if
0
not
in
data
:
finfo
.
Type
=
'TEXT'
fp
.
seek
(
0
,
2
)
dsize
=
fp
.
tell
()
dir
,
file
=
os
.
path
.
split
(
name
)
file
=
file
.
replace
(
':'
,
'-'
,
1
)
return
file
,
finfo
,
dsize
,
0
...
...
@@ -140,19 +139,26 @@ class _Rlecoderengine:
class
BinHex
:
def
__init__
(
self
,
name_finfo_dlen_rlen
,
ofp
):
name
,
finfo
,
dlen
,
rlen
=
name_finfo_dlen_rlen
close_on_error
=
False
if
isinstance
(
ofp
,
str
):
ofname
=
ofp
ofp
=
io
.
open
(
ofname
,
'wb'
)
ofp
.
write
(
b'(This file must be converted with BinHex 4.0)
\
r
\
r
:'
)
hqxer
=
_Hqxcoderengine
(
ofp
)
self
.
ofp
=
_Rlecoderengine
(
hqxer
)
self
.
crc
=
0
if
finfo
is
None
:
finfo
=
FInfo
()
self
.
dlen
=
dlen
self
.
rlen
=
rlen
self
.
_writeinfo
(
name
,
finfo
)
self
.
state
=
_DID_HEADER
close_on_error
=
True
try
:
ofp
.
write
(
b'(This file must be converted with BinHex 4.0)
\
r
\
r
:'
)
hqxer
=
_Hqxcoderengine
(
ofp
)
self
.
ofp
=
_Rlecoderengine
(
hqxer
)
self
.
crc
=
0
if
finfo
is
None
:
finfo
=
FInfo
()
self
.
dlen
=
dlen
self
.
rlen
=
rlen
self
.
_writeinfo
(
name
,
finfo
)
self
.
state
=
_DID_HEADER
except
:
if
close_on_error
:
ofp
.
close
()
raise
def
_writeinfo
(
self
,
name
,
finfo
):
nl
=
len
(
name
)
...
...
Lib/test/test_binhex.py
View file @
b3c728fd
...
...
@@ -15,10 +15,12 @@ class BinHexTestCase(unittest.TestCase):
def
setUp
(
self
):
self
.
fname1
=
support
.
TESTFN
+
"1"
self
.
fname2
=
support
.
TESTFN
+
"2"
self
.
fname3
=
support
.
TESTFN
+
"very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
def
tearDown
(
self
):
support
.
unlink
(
self
.
fname1
)
support
.
unlink
(
self
.
fname2
)
support
.
unlink
(
self
.
fname3
)
DATA
=
b'Jack is my hero'
...
...
@@ -37,6 +39,15 @@ class BinHexTestCase(unittest.TestCase):
self
.
assertEqual
(
self
.
DATA
,
finish
)
def
test_binhex_error_on_long_filename
(
self
):
"""
The testcase fails if no exception is raised when a filename parameter provided to binhex.binhex()
is too long, or if the exception raised in binhex.binhex() is not an instance of binhex.Error.
"""
f3
=
open
(
self
.
fname3
,
'wb'
)
f3
.
close
()
self
.
assertRaises
(
binhex
.
Error
,
binhex
.
binhex
,
self
.
fname3
,
self
.
fname2
)
def
test_main
():
support
.
run_unittest
(
BinHexTestCase
)
...
...
Misc/ACKS
View file @
b3c728fd
...
...
@@ -447,6 +447,7 @@ Tamito Kajiyama
Peter van Kampen
Rafe Kaplan
Jacob Kaplan-Moss
Arkady Koplyarov
Lou Kates
Hiroaki Kawai
Sebastien Keim
...
...
Misc/NEWS
View file @
b3c728fd
...
...
@@ -40,6 +40,8 @@ Core and Builtins
Library
-------
-
Issue
#
11577
:
fix
ResourceWarning
triggered
by
improved
binhex
test
coverage
-
Issue
#
11401
:
fix
handling
of
headers
with
no
value
;
this
fixes
a
regression
relative
to
Python2
and
the
result
is
now
the
same
as
it
was
in
Python2
.
...
...
@@ -129,6 +131,8 @@ Tools/Demos
Tests
-----
-
Issue
#
11577
:
improve
test
coverage
of
binhex
.
py
.
Patch
by
Arkady
Koplyarov
.
-
Issue
#
11578
:
added
test
for
the
timeit
module
.
Patch
Michael
Henry
.
-
Issue
#
11503
:
improve
test
coverage
of
posixpath
.
py
.
Patch
by
Evan
Dandrea
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment