Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
0582e130
Commit
0582e130
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
fix a bug in read_in_file
parent
a5d079b8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/files.py
+3
-2
3 additions, 2 deletions
satella/files.py
tests/test_files.py
+3
-0
3 additions, 0 deletions
tests/test_files.py
with
8 additions
and
3 deletions
CHANGELOG.md
+
1
−
0
View file @
0582e130
...
@@ -3,3 +3,4 @@
...
@@ -3,3 +3,4 @@
*
added
`encoding`
to
`read_lines`
*
added
`encoding`
to
`read_lines`
*
added
`none_if_false`
*
added
`none_if_false`
*
fixed import mishap in
`satella.coding.transforms`
with
`hashables_to_int`
*
fixed import mishap in
`satella.coding.transforms`
with
`hashables_to_int`
*
fixed
`read_in_file`
if file does not exist and default is not set
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
0582e130
__version__
=
'
2.14.33a
3
'
__version__
=
'
2.14.33a
4
'
This diff is collapsed.
Click to expand it.
satella/files.py
+
3
−
2
View file @
0582e130
...
@@ -168,6 +168,7 @@ def read_in_file(path: str, encoding: tp.Optional[str] = None,
...
@@ -168,6 +168,7 @@ def read_in_file(path: str, encoding: tp.Optional[str] = None,
:param default: value to return when the file does not exist. Default (None) will raise a
:param default: value to return when the file does not exist. Default (None) will raise a
FileNotFoundError
FileNotFoundError
:return: file content, either decoded as a str, or not as bytes
:return: file content, either decoded as a str, or not as bytes
:raises FileNotFoundError: file did not exist and default was not set
"""
"""
if
os
.
path
.
isdir
(
path
):
if
os
.
path
.
isdir
(
path
):
if
default
is
not
_NOTSET
:
if
default
is
not
_NOTSET
:
...
@@ -178,9 +179,9 @@ def read_in_file(path: str, encoding: tp.Optional[str] = None,
...
@@ -178,9 +179,9 @@ def read_in_file(path: str, encoding: tp.Optional[str] = None,
if
encoding
is
None
:
if
encoding
is
None
:
file
=
open
(
path
,
'
rb
'
)
file
=
open
(
path
,
'
rb
'
)
else
:
else
:
file
=
codecs
.
open
(
path
,
'
r
b
'
,
encoding
)
file
=
codecs
.
open
(
path
,
'
r
'
,
encoding
)
except
FileNotFoundError
:
except
FileNotFoundError
:
if
default
:
if
default
is
not
_NOTSET
:
return
default
return
default
raise
raise
...
...
This diff is collapsed.
Click to expand it.
tests/test_files.py
+
3
−
0
View file @
0582e130
...
@@ -16,6 +16,9 @@ def putfile(path: str) -> None:
...
@@ -16,6 +16,9 @@ def putfile(path: str) -> None:
class
TestFiles
(
unittest
.
TestCase
):
class
TestFiles
(
unittest
.
TestCase
):
def
test_read_nonexistent_file
(
self
):
self
.
assertRaises
(
FileNotFoundError
,
lambda
:
read_in_file
(
'
moot
'
))
def
test_read_lines
(
self
):
def
test_read_lines
(
self
):
lines
=
read_lines
(
'
LICENSE
'
)
lines
=
read_lines
(
'
LICENSE
'
)
self
.
assertTrue
(
all
(
lines
))
self
.
assertTrue
(
all
(
lines
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment