Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
9441bd72
Commit
9441bd72
authored
Oct 18, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'devel' of
git://github.com/willthames/ansible
into devel
parents
a94a228c
3934cd76
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
2 deletions
+67
-2
lib/ansible/constants.py
+0
-2
test/TestConstants.py
+64
-0
test/ansible.cfg
+3
-0
No files found.
lib/ansible/constants.py
View file @
9441bd72
...
...
@@ -29,8 +29,6 @@ def get_config(p, section, key, env_var, default):
try
:
return
p
.
get
(
section
,
key
)
except
:
if
env_var
is
not
None
:
return
os
.
environ
.
get
(
env_var
,
default
)
return
default
else
:
return
default
...
...
test/TestConstants.py
0 → 100644
View file @
9441bd72
# -*- coding: utf-8 -*-
import
unittest
from
ansible.constants
import
get_config
import
ConfigParser
import
random
import
string
import
os
def
random_string
(
length
):
return
''
.
join
(
random
.
choice
(
string
.
ascii_uppercase
)
for
x
in
range
(
6
))
p
=
ConfigParser
.
ConfigParser
()
p
.
read
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'ansible.cfg'
))
class
TestConstants
(
unittest
.
TestCase
):
#####################################
### get_config unit tests
def
test_configfile_and_env_both_set
(
self
):
r
=
random_string
(
6
)
env_var
=
'ANSIBLE_TEST_
%
s'
%
r
os
.
environ
[
env_var
]
=
r
res
=
get_config
(
p
,
'defaults'
,
'test_key'
,
env_var
,
'default'
)
del
os
.
environ
[
env_var
]
assert
res
==
r
def
test_configfile_set_env_not_set
(
self
):
r
=
random_string
(
6
)
env_var
=
'ANSIBLE_TEST_
%
s'
%
r
assert
env_var
not
in
os
.
environ
res
=
get_config
(
p
,
'defaults'
,
'test_key'
,
env_var
,
'default'
)
print
res
assert
res
==
'test_value'
def
test_configfile_not_set_env_set
(
self
):
r
=
random_string
(
6
)
env_var
=
'ANSIBLE_TEST_
%
s'
%
r
os
.
environ
[
env_var
]
=
r
res
=
get_config
(
p
,
'defaults'
,
'doesnt_exist'
,
env_var
,
'default'
)
del
os
.
environ
[
env_var
]
assert
res
==
r
def
test_configfile_not_set_env_not_set
(
self
):
r
=
random_string
(
6
)
env_var
=
'ANSIBLE_TEST_
%
s'
%
r
assert
env_var
not
in
os
.
environ
res
=
get_config
(
p
,
'defaults'
,
'doesnt_exist'
,
env_var
,
'default'
)
assert
res
==
'default'
test/ansible.cfg
0 → 100644
View file @
9441bd72
[defaults]
test_key = test_value
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