Completed
Pull Request — master (#160)
by
unknown
35s
created

test_make_dotfile()   B

Complexity

Conditions 6

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
dl 0
loc 13
rs 8
c 0
b 0
f 0
1
from uuid import uuid1
2
3
import pytest
4
5
from click.testing import CliRunner
6
7
from flask_jsondash.data_utils import filetree_digraph
8
9
10
# def test_make_dotfile(tmpdir):
11
#     uid = str(uuid1())
12
#     tmp = tmpdir.mkdir(uid)
13
#     for i in range(4):
14
#         tmp.join('{}.txt'.format(i)).write('{}'.format(i))
15
#     data = filetree_digraph.make_dotfile(tmp.strpath)
16
#     # Ensure wrapping lines are proper digraph format.
17
#     assert data.startswith('digraph {\n')
18
#     assert data.endswith('\n}\n')
19
#     lines = data.split('\n')
20
#     # Ensure each line has the right dotfile format.
21
#     for i, line in enumerate(lines[1:len(lines) - 2]):
22
#         assert line == '\t"{0}" -> "{1}.txt";'.format(uid, i)
23
24
25
def test_make_dotfile_skip_empty(monkeypatch, tmpdir):
26
    uid = str(uuid1())
27
    tmp = tmpdir.mkdir(uid)
28
    # Add a bunch of empty pointers
29
    results = [' ->' for _ in range(10)] + ['foo -> bar']
30
    monkeypatch.setattr(
31
        filetree_digraph, 'path_hierarchy', lambda *a, **k: results)
32
    data = filetree_digraph.make_dotfile(tmp.strpath)
33
    assert data == 'digraph {\n\tfoo -> bar;\n}\n'
34
35
36
def test_make_dotfile_invalid_path():
37
    with pytest.raises(OSError):
38
        filetree_digraph.make_dotfile('invalid-path')
39
40
41
def test_make_dotfile_invalid_path_none():
42
    with pytest.raises(AssertionError):
43
        filetree_digraph.make_dotfile(None)
44
45
46
def test_get_dotfile_tree_invalid_path(tmpdir):
47
    runner = CliRunner()
48
    result = runner.invoke(filetree_digraph.get_dotfile_tree, ['-p', '.'])
49
    assert result.exit_code == -1
50
    assert isinstance(result.exception, ValueError)
51
    assert 'Running in the same directory when no' in str(result.exception)
52
53
54
def test_get_dotfile_tree_valid_path(tmpdir):
55
    uid = str(uuid1())
56
    tmp = tmpdir.mkdir(uid)
57
    tmppath = str(tmp.realpath())
58
    runner = CliRunner()
59
    result = runner.invoke(
60
        filetree_digraph.get_dotfile_tree, ['-p', tmppath])
61
    assert result.exit_code == 0
62
    assert 'digraph' in result.output
63
64
65
def test_get_dotfile_tree_valid_path_dotfile(tmpdir):
66
    uid = str(uuid1())
67
    tmp = tmpdir.mkdir(uid)
68
    tmpfile = tmp.join('foo.dot')
69
    tmpfilepath = str(tmpfile.realpath())
70
    tmppath = str(tmp.realpath())
71
    runner = CliRunner()
72
    result = runner.invoke(
73
        filetree_digraph.get_dotfile_tree, ['-p', tmppath, '-d', tmpfilepath])
74
    assert result.exit_code == 0
75
    with open(tmpfilepath, 'r') as res:
76
        assert 'digraph' in str(res.read())
77