Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mercurial-devel
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
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
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
mercurial
mercurial-devel
Commits
fa2b596d
Commit
fa2b596d
authored
13 years ago
by
Sune Foldager
Browse files
Options
Downloads
Patches
Plain Diff
ui: add configint function and tests
parent
d8ba6fb2
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
mercurial/ui.py
+57
-2
57 additions, 2 deletions
mercurial/ui.py
tests/test-doctest.py
+3
-0
3 additions, 0 deletions
tests/test-doctest.py
tests/test-ui-config.py
+18
-1
18 additions, 1 deletion
tests/test-ui-config.py
tests/test-ui-config.py.out
+7
-2
7 additions, 2 deletions
tests/test-ui-config.py.out
with
85 additions
and
5 deletions
mercurial/ui.py
+
57
−
2
View file @
fa2b596d
...
...
@@ -164,6 +164,26 @@
return
v
def
configbool
(
self
,
section
,
name
,
default
=
False
,
untrusted
=
False
):
"""
parse a configuration element as a boolean
>>>
u
=
ui
();
s
=
'
foo
'
>>>
u
.
setconfig
(
s
,
'
true
'
,
'
yes
'
)
>>>
u
.
configbool
(
s
,
'
true
'
)
True
>>>
u
.
setconfig
(
s
,
'
false
'
,
'
no
'
)
>>>
u
.
configbool
(
s
,
'
false
'
)
False
>>>
u
.
configbool
(
s
,
'
unknown
'
)
False
>>>
u
.
configbool
(
s
,
'
unknown
'
,
True
)
True
>>>
u
.
setconfig
(
s
,
'
invalid
'
,
'
somevalue
'
)
>>>
u
.
configbool
(
s
,
'
invalid
'
)
Traceback
(
most
recent
call
last
):
...
ConfigError
:
foo
.
invalid
is
not
a
boolean
(
'
somevalue
'
)
"""
v
=
self
.
config
(
section
,
name
,
None
,
untrusted
)
if
v
is
None
:
return
default
...
...
@@ -171,7 +191,7 @@
return
v
b
=
util
.
parsebool
(
v
)
if
b
is
None
:
raise
error
.
ConfigError
(
_
(
"
%s.%s not a boolean (
'
%s
'
)
"
)
raise
error
.
ConfigError
(
_
(
"
%s.%s
is
not a boolean (
'
%s
'
)
"
)
%
(
section
,
name
,
v
))
return
b
...
...
@@ -175,4 +195,32 @@
%
(
section
,
name
,
v
))
return
b
def
configint
(
self
,
section
,
name
,
default
=
None
,
untrusted
=
False
):
"""
parse a configuration element as an integer
>>>
u
=
ui
();
s
=
'
foo
'
>>>
u
.
setconfig
(
s
,
'
int1
'
,
'
42
'
)
>>>
u
.
configint
(
s
,
'
int1
'
)
42
>>>
u
.
setconfig
(
s
,
'
int2
'
,
'
-42
'
)
>>>
u
.
configint
(
s
,
'
int2
'
)
-
42
>>>
u
.
configint
(
s
,
'
unknown
'
,
7
)
7
>>>
u
.
setconfig
(
s
,
'
invalid
'
,
'
somevalue
'
)
>>>
u
.
configint
(
s
,
'
invalid
'
)
Traceback
(
most
recent
call
last
):
...
ConfigError
:
foo
.
invalid
is
not
an
integer
(
'
somevalue
'
)
"""
v
=
self
.
config
(
section
,
name
,
None
,
untrusted
)
if
v
is
None
:
return
default
try
:
return
int
(
v
)
except
ValueError
:
raise
error
.
ConfigError
(
_
(
"
%s.%s is not an integer (
'
%s
'
)
"
)
%
(
section
,
name
,
v
))
def
configlist
(
self
,
section
,
name
,
default
=
None
,
untrusted
=
False
):
...
...
@@ -178,5 +226,12 @@
def
configlist
(
self
,
section
,
name
,
default
=
None
,
untrusted
=
False
):
"""
Return a list of comma/space separated strings
"""
"""
parse a configuration element as a list of comma/space separated
strings
>>>
u
=
ui
();
s
=
'
foo
'
>>>
u
.
setconfig
(
s
,
'
list1
'
,
'
this,is
"
a small
"
,test
'
)
>>>
u
.
configlist
(
s
,
'
list1
'
)
[
'
this
'
,
'
is
'
,
'
a small
'
,
'
test
'
]
"""
def
_parse_plain
(
parts
,
s
,
offset
):
whitespace
=
False
...
...
This diff is collapsed.
Click to expand it.
tests/test-doctest.py
+
3
−
0
View file @
fa2b596d
...
...
@@ -16,6 +16,9 @@
import
mercurial.store
doctest
.
testmod
(
mercurial
.
store
)
import
mercurial.ui
doctest
.
testmod
(
mercurial
.
ui
)
import
mercurial.url
doctest
.
testmod
(
mercurial
.
url
)
...
...
This diff is collapsed.
Click to expand it.
tests/test-ui-config.py
+
18
−
1
View file @
fa2b596d
...
...
@@ -5,6 +5,10 @@
'
values.string=string value
'
,
'
values.bool1=true
'
,
'
values.bool2=false
'
,
'
values.boolinvalid=foo
'
,
'
values.int1=42
'
,
'
values.int2=-42
'
,
'
values.intinvalid=foo
'
,
'
lists.list1=foo
'
,
'
lists.list2=foo bar baz
'
,
'
lists.list3=alice, bob
'
,
...
...
@@ -23,7 +27,7 @@
'
lists.list16=
"
longer quotation
"
with
"
no ending quotation
'
,
'
lists.list17=this is
\\
"
"
not a quotation mark
"'
,
'
lists.list18=
\n
\n\n
ding
\n
dong
'
,
])
])
print
repr
(
testui
.
configitems
(
'
values
'
))
print
repr
(
testui
.
configitems
(
'
lists
'
))
...
...
@@ -43,6 +47,9 @@
print
repr
(
testui
.
configbool
(
'
values
'
,
'
unknown
'
))
print
repr
(
testui
.
configbool
(
'
values
'
,
'
unknown
'
,
True
))
print
"
---
"
print
repr
(
testui
.
configint
(
'
values
'
,
'
int1
'
))
print
repr
(
testui
.
configint
(
'
values
'
,
'
int2
'
))
print
"
---
"
print
repr
(
testui
.
configlist
(
'
lists
'
,
'
list1
'
))
print
repr
(
testui
.
configlist
(
'
lists
'
,
'
list2
'
))
print
repr
(
testui
.
configlist
(
'
lists
'
,
'
list3
'
))
...
...
@@ -79,3 +86,13 @@
# values that aren't strings should work
testui
.
setconfig
(
'
hook
'
,
'
commit
'
,
function
)
print
function
==
testui
.
config
(
'
hook
'
,
'
commit
'
)
# invalid values
try
:
testui
.
configbool
(
'
values
'
,
'
boolinvalid
'
)
except
error
.
ConfigError
:
print
'
boolinvalid
'
try
:
testui
.
configint
(
'
values
'
,
'
intinvalid
'
)
except
error
.
ConfigError
:
print
'
intinvalid
'
This diff is collapsed.
Click to expand it.
tests/test-ui-config.py.out
+
7
−
2
View file @
fa2b596d
[('string', 'string value'), ('bool1', 'true'), ('bool2', 'false')]
[('string', 'string value'), ('bool1', 'true'), ('bool2', 'false')
, ('boolinvalid', 'foo'), ('int1', '42'), ('int2', '-42'), ('intinvalid', 'foo')
]
[('list1', 'foo'), ('list2', 'foo bar baz'), ('list3', 'alice, bob'), ('list4', 'foo bar baz alice, bob'), ('list5', 'abc d"ef"g "hij def"'), ('list6', '"hello world", "how are you?"'), ('list7', 'Do"Not"Separate'), ('list8', '"Do"Separate'), ('list9', '"Do\\"NotSeparate"'), ('list10', 'string "with extraneous" quotation mark"'), ('list11', 'x, y'), ('list12', '"x", "y"'), ('list13', '""" key = "x", "y" """'), ('list14', ',,,, '), ('list15', '" just with starting quotation'), ('list16', '"longer quotation" with "no ending quotation'), ('list17', 'this is \\" "not a quotation mark"'), ('list18', '\n \n\nding\ndong')]
---
'string value'
...
...
@@ -6,10 +6,10 @@
'false'
None
---
values.string not a boolean ('string value')
values.string
is
not a boolean ('string value')
True
False
False
False
True
---
...
...
@@ -10,9 +10,12 @@
True
False
False
False
True
---
42
-42
---
['foo']
['foo', 'bar', 'baz']
['alice', 'bob']
...
...
@@ -42,3 +45,5 @@
['foo', 'bar']
None
True
boolinvalid
intinvalid
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