Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.cmdline
Commits
88a0b919
Commit
88a0b919
authored
May 23, 2018
by
Flavio TARSETTI
Browse files
[config/common] added tests for editor
parent
bd3140f9
Pipeline
#20430
passed with stages
in 47 minutes and 14 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/cmdline/test/test_config.py
View file @
88a0b919
...
...
@@ -38,6 +38,7 @@ from . import tmp_prefix, temp_cwd
from
..scripts.beat
import
main
from
beat.core.test.utils
import
cleanup
from
..
import
config
from
..
import
common
def
call
(
*
args
,
**
kwargs
):
...
...
@@ -136,3 +137,106 @@ def test_get_bad_config_key():
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_get_token
():
nose
.
tools
.
eq_
(
call
(
'config'
,
'get'
,
'token'
),
0
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_get_editor
():
nose
.
tools
.
eq_
(
call
(
'config'
,
'get'
,
'editor'
),
0
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_set_local_editor
():
editor_value
=
'editor'
with
temp_cwd
()
as
d
:
nose
.
tools
.
eq_
(
call
(
'config'
,
'set'
,
'--local'
,
'editor'
,
editor_value
),
0
)
config
=
os
.
path
.
join
(
d
,
'.beatrc'
)
assert
os
.
path
.
exists
(
config
)
with
open
(
config
,
'rt'
)
as
f
:
contents
=
simplejson
.
load
(
f
)
assert
contents
[
'editor'
]
==
editor_value
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_check_editor_system_no_editor_set
():
editor
=
None
os
.
environ
[
'VISUAL'
]
=
''
os
.
environ
[
'EDITOR'
]
=
''
cmd
=
"%s %s && %s %s"
%
(
'mkdir -p'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
),
'touch'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
))
os
.
system
(
cmd
)
result
=
common
.
edit_local_file
(
tmp_prefix
,
editor
,
'plotter'
,
"test"
)
assert
result
==
1
with
open
(
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
),
'r'
)
as
f
:
read_data
=
f
.
read
().
split
(
'
\n
'
)[
0
]
f
.
closed
assert
len
(
read_data
)
==
0
cmd
=
"%s %s"
%
(
'rm -fr'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
))
os
.
system
(
cmd
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_check_editor_system_no_local_editor
():
editor
=
None
os
.
environ
[
'VISUAL'
]
=
'echo "2" >'
os
.
environ
[
'EDITOR'
]
=
'echo "3" >'
cmd
=
"%s %s && %s %s"
%
(
'mkdir -p'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
),
'touch'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
))
os
.
system
(
cmd
)
result
=
common
.
edit_local_file
(
tmp_prefix
,
editor
,
'plotter'
,
"test"
)
assert
result
==
0
with
open
(
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
),
'r'
)
as
f
:
read_data
=
f
.
read
().
split
(
'
\n
'
)[
0
]
f
.
closed
assert
len
(
read_data
)
==
1
assert
read_data
==
"2"
cmd
=
"%s %s"
%
(
'rm -fr'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
))
os
.
system
(
cmd
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_check_editor_system_local_editor_set
():
editor
=
'echo "1" >'
os
.
environ
[
'VISUAL'
]
=
'echo "2" >'
os
.
environ
[
'EDITOR'
]
=
'echo "3" >'
cmd
=
"%s %s && %s %s"
%
(
'mkdir -p'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
),
'touch'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
))
os
.
system
(
cmd
)
result
=
common
.
edit_local_file
(
tmp_prefix
,
editor
,
'plotter'
,
"test"
)
assert
result
==
0
with
open
(
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
),
'r'
)
as
f
:
read_data
=
f
.
read
().
split
(
'
\n
'
)[
0
]
f
.
closed
assert
len
(
read_data
)
==
1
assert
read_data
==
"1"
cmd
=
"%s %s"
%
(
'rm -fr'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
))
os
.
system
(
cmd
)
@
nose
.
tools
.
with_setup
(
teardown
=
cleanup
)
def
test_check_editor_system_no_local_editor_no_visual
():
editor
=
None
os
.
environ
[
'VISUAL'
]
=
''
os
.
environ
[
'EDITOR'
]
=
'echo "3" >'
cmd
=
"%s %s && %s %s"
%
(
'mkdir -p'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
),
'touch'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
))
os
.
system
(
cmd
)
result
=
common
.
edit_local_file
(
tmp_prefix
,
editor
,
'plotter'
,
"test"
)
assert
result
==
0
with
open
(
os
.
path
.
join
(
tmp_prefix
,
'plotters'
,
'test.py'
),
'r'
)
as
f
:
read_data
=
f
.
read
().
split
(
'
\n
'
)[
0
]
f
.
closed
assert
len
(
read_data
)
==
1
assert
read_data
==
"3"
cmd
=
"%s %s"
%
(
'rm -fr'
,
os
.
path
.
join
(
tmp_prefix
,
'plotters'
))
os
.
system
(
cmd
)
Write
Preview
Supports
Markdown
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