Commit 3fed6c19 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[test] refactored edit command tests

parent 5dc1cc7f
Pipeline #20456 passed with stages
in 34 minutes and 14 seconds
......@@ -155,47 +155,54 @@ def test_set_local_editor():
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'))
def create_touch_file(tmp_prefix, 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
return result
def read_data(tmp_prefix):
with open(os.path.join(tmp_prefix, 'plotters', 'test.py'), 'r') as f:
read_data = f.read().split('\n')[0]
f.closed
return read_data
assert len(read_data) == 0
cmd = "%s %s"%('rm -fr', os.path.join(tmp_prefix, 'plotters'))
def clean_tmp_files(tmp_prefix):
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_editor_set():
editor = None
os.environ['VISUAL'] = ''
os.environ['EDITOR'] = ''
result = create_touch_file(tmp_prefix, editor)
assert result == 1
data = read_data(tmp_prefix)
assert len(data) == 0
clean_tmp_files(tmp_prefix)
@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")
result = create_touch_file(tmp_prefix, editor)
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"
data = read_data(tmp_prefix)
assert len(data) == 1
assert data == "2"
cmd = "%s %s"%('rm -fr', os.path.join(tmp_prefix, 'plotters'))
os.system(cmd)
clean_tmp_files(tmp_prefix)
@nose.tools.with_setup(teardown=cleanup)
......@@ -204,20 +211,14 @@ def test_check_editor_system_local_editor_set():
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")
result = create_touch_file(tmp_prefix, editor)
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"
data = read_data(tmp_prefix)
assert len(data) == 1
assert data == "1"
cmd = "%s %s"%('rm -fr', os.path.join(tmp_prefix, 'plotters'))
os.system(cmd)
clean_tmp_files(tmp_prefix)
@nose.tools.with_setup(teardown=cleanup)
......@@ -226,17 +227,11 @@ def test_check_editor_system_no_local_editor_no_visual():
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")
result = create_touch_file(tmp_prefix, editor)
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
data = read_data(tmp_prefix)
assert len(data) == 1
assert data == "3"
assert len(read_data) == 1
assert read_data == "3"
cmd = "%s %s"%('rm -fr', os.path.join(tmp_prefix, 'plotters'))
os.system(cmd)
clean_tmp_files(tmp_prefix)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment