Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
07d22e5e
Kaydet (Commit)
07d22e5e
authored
Haz 23, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge heads
üst
c89533f7
82276964
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
13 deletions
+65
-13
configparser.py
Lib/configparser.py
+2
-2
test_configparser.py
Lib/test/test_configparser.py
+63
-11
No files found.
Lib/configparser.py
Dosyayı görüntüle @
07d22e5e
...
@@ -191,7 +191,7 @@ class DuplicateSectionError(Error):
...
@@ -191,7 +191,7 @@ class DuplicateSectionError(Error):
def
__init__
(
self
,
section
,
source
=
None
,
lineno
=
None
):
def
__init__
(
self
,
section
,
source
=
None
,
lineno
=
None
):
msg
=
[
repr
(
section
),
" already exists"
]
msg
=
[
repr
(
section
),
" already exists"
]
if
source
is
not
None
:
if
source
is
not
None
:
message
=
[
"While reading from "
,
source
]
message
=
[
"While reading from "
,
repr
(
source
)
]
if
lineno
is
not
None
:
if
lineno
is
not
None
:
message
.
append
(
" [line {0:2d}]"
.
format
(
lineno
))
message
.
append
(
" [line {0:2d}]"
.
format
(
lineno
))
message
.
append
(
": section "
)
message
.
append
(
": section "
)
...
@@ -217,7 +217,7 @@ class DuplicateOptionError(Error):
...
@@ -217,7 +217,7 @@ class DuplicateOptionError(Error):
msg
=
[
repr
(
option
),
" in section "
,
repr
(
section
),
msg
=
[
repr
(
option
),
" in section "
,
repr
(
section
),
" already exists"
]
" already exists"
]
if
source
is
not
None
:
if
source
is
not
None
:
message
=
[
"While reading from "
,
source
]
message
=
[
"While reading from "
,
repr
(
source
)
]
if
lineno
is
not
None
:
if
lineno
is
not
None
:
message
.
append
(
" [line {0:2d}]"
.
format
(
lineno
))
message
.
append
(
" [line {0:2d}]"
.
format
(
lineno
))
message
.
append
(
": option "
)
message
.
append
(
": option "
)
...
...
Lib/test/test_configparser.py
Dosyayı görüntüle @
07d22e5e
...
@@ -626,15 +626,15 @@ boolean {0[0]} NO
...
@@ -626,15 +626,15 @@ boolean {0[0]} NO
oops{equals}this won't
oops{equals}this won't
"""
.
format
(
equals
=
self
.
delimiters
[
0
])),
source
=
'<foo-bar>'
)
"""
.
format
(
equals
=
self
.
delimiters
[
0
])),
source
=
'<foo-bar>'
)
e
=
cm
.
exception
e
=
cm
.
exception
self
.
assertEqual
(
str
(
e
),
"While reading from
<foo-bar> [line 5]:
"
self
.
assertEqual
(
str
(
e
),
"While reading from
'<foo-bar>'
"
"section 'Foo' already exists"
)
"
[line 5]:
section 'Foo' already exists"
)
self
.
assertEqual
(
e
.
args
,
(
"Foo"
,
'<foo-bar>'
,
5
))
self
.
assertEqual
(
e
.
args
,
(
"Foo"
,
'<foo-bar>'
,
5
))
with
self
.
assertRaises
(
configparser
.
DuplicateOptionError
)
as
cm
:
with
self
.
assertRaises
(
configparser
.
DuplicateOptionError
)
as
cm
:
cf
.
read_dict
({
'Bar'
:
{
'opt'
:
'val'
,
'OPT'
:
'is really `opt`'
}})
cf
.
read_dict
({
'Bar'
:
{
'opt'
:
'val'
,
'OPT'
:
'is really `opt`'
}})
e
=
cm
.
exception
e
=
cm
.
exception
self
.
assertEqual
(
str
(
e
),
"While reading from
<dict>: option 'opt'
"
self
.
assertEqual
(
str
(
e
),
"While reading from
'<dict>': option
"
"in section 'Bar' already exists"
)
"
'opt'
in section 'Bar' already exists"
)
self
.
assertEqual
(
e
.
args
,
(
"Bar"
,
"opt"
,
"<dict>"
,
None
))
self
.
assertEqual
(
e
.
args
,
(
"Bar"
,
"opt"
,
"<dict>"
,
None
))
def
test_write
(
self
):
def
test_write
(
self
):
...
@@ -1419,13 +1419,18 @@ def readline_generator(f):
...
@@ -1419,13 +1419,18 @@ def readline_generator(f):
class
ReadFileTestCase
(
unittest
.
TestCase
):
class
ReadFileTestCase
(
unittest
.
TestCase
):
def
test_file
(
self
):
def
test_file
(
self
):
file_path
=
support
.
findfile
(
"cfgparser.1"
)
file_paths
=
[
support
.
findfile
(
"cfgparser.1"
)]
parser
=
configparser
.
ConfigParser
()
try
:
with
open
(
file_path
)
as
f
:
file_paths
.
append
(
file_paths
[
0
]
.
encode
(
'utf8'
))
parser
.
read_file
(
f
)
except
UnicodeEncodeError
:
self
.
assertIn
(
"Foo Bar"
,
parser
)
pass
# unfortunately we can't test bytes on this path
self
.
assertIn
(
"foo"
,
parser
[
"Foo Bar"
])
for
file_path
in
file_paths
:
self
.
assertEqual
(
parser
[
"Foo Bar"
][
"foo"
],
"newbar"
)
parser
=
configparser
.
ConfigParser
()
with
open
(
file_path
)
as
f
:
parser
.
read_file
(
f
)
self
.
assertIn
(
"Foo Bar"
,
parser
)
self
.
assertIn
(
"foo"
,
parser
[
"Foo Bar"
])
self
.
assertEqual
(
parser
[
"Foo Bar"
][
"foo"
],
"newbar"
)
def
test_iterable
(
self
):
def
test_iterable
(
self
):
lines
=
textwrap
.
dedent
(
"""
lines
=
textwrap
.
dedent
(
"""
...
@@ -1447,6 +1452,53 @@ class ReadFileTestCase(unittest.TestCase):
...
@@ -1447,6 +1452,53 @@ class ReadFileTestCase(unittest.TestCase):
self
.
assertIn
(
"foo"
,
parser
[
"Foo Bar"
])
self
.
assertIn
(
"foo"
,
parser
[
"Foo Bar"
])
self
.
assertEqual
(
parser
[
"Foo Bar"
][
"foo"
],
"newbar"
)
self
.
assertEqual
(
parser
[
"Foo Bar"
][
"foo"
],
"newbar"
)
def
test_source_as_bytes
(
self
):
"""Issue #18260."""
lines
=
textwrap
.
dedent
(
"""
[badbad]
[badbad]"""
)
.
strip
()
.
split
(
'
\n
'
)
parser
=
configparser
.
ConfigParser
()
with
self
.
assertRaises
(
configparser
.
DuplicateSectionError
)
as
dse
:
parser
.
read_file
(
lines
,
source
=
b
"badbad"
)
self
.
assertEqual
(
str
(
dse
.
exception
),
"While reading from b'badbad' [line 2]: section 'badbad' "
"already exists"
)
lines
=
textwrap
.
dedent
(
"""
[badbad]
bad = bad
bad = bad"""
)
.
strip
()
.
split
(
'
\n
'
)
parser
=
configparser
.
ConfigParser
()
with
self
.
assertRaises
(
configparser
.
DuplicateOptionError
)
as
dse
:
parser
.
read_file
(
lines
,
source
=
b
"badbad"
)
self
.
assertEqual
(
str
(
dse
.
exception
),
"While reading from b'badbad' [line 3]: option 'bad' in section "
"'badbad' already exists"
)
lines
=
textwrap
.
dedent
(
"""
[badbad]
= bad"""
)
.
strip
()
.
split
(
'
\n
'
)
parser
=
configparser
.
ConfigParser
()
with
self
.
assertRaises
(
configparser
.
ParsingError
)
as
dse
:
parser
.
read_file
(
lines
,
source
=
b
"badbad"
)
self
.
assertEqual
(
str
(
dse
.
exception
),
"Source contains parsing errors: b'badbad'
\n\t
[line 2]: '= bad'"
)
lines
=
textwrap
.
dedent
(
"""
[badbad
bad = bad"""
)
.
strip
()
.
split
(
'
\n
'
)
parser
=
configparser
.
ConfigParser
()
with
self
.
assertRaises
(
configparser
.
MissingSectionHeaderError
)
as
dse
:
parser
.
read_file
(
lines
,
source
=
b
"badbad"
)
self
.
assertEqual
(
str
(
dse
.
exception
),
"File contains no section headers.
\n
file: b'badbad', line: 1
\n
"
"'[badbad'"
)
class
CoverageOneHundredTestCase
(
unittest
.
TestCase
):
class
CoverageOneHundredTestCase
(
unittest
.
TestCase
):
"""Covers edge cases in the codebase."""
"""Covers edge cases in the codebase."""
...
...
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