Passed
Push — main ( 450e43...cb7df0 )
by J
03:50
created

tests.main_test.test_install_no_run()   A

Complexity

Conditions 3

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 16
rs 9.7
c 0
b 0
f 0
cc 3
nop 1
1
# -*- coding: utf-8 -*-
2
import sys
3
from tempfile import TemporaryDirectory
4
from unittest.mock import patch
5
6
import pytest
7
8
from devenv.devenv import main, parse_args
9
10
11
def test_empty_dir():
12
    # usually we'd use pytest's tmp_path, but it wasn't cleaning up in this instance
13
    with TemporaryDirectory() as tmpdir:
14
        with patch.object(
15
            sys, "argv", ["devenv", "--scripts_path", tmpdir, "python", "devenv"]
16
        ):
17
            args = parse_args()
18
            with pytest.raises(SystemError):
19
                main(args)
20
21
22
def test_install_no_run(tmp_path):
23
    scripts_path = tmp_path / "scripts"
24
    with patch.object(
25
        sys,
26
        "argv",
27
        [
28
            "devenv",
29
            None,
30
            None,
31
            "--install_scripts",
32
            "--scripts_path",
33
            str(scripts_path),
34
        ],
35
    ):
36
        with pytest.raises(SystemExit):
37
            main(parse_args())
38
39
40
def test_permission_error(tmp_path):
41
    scripts_path = tmp_path / "scripts"
42
    scripts_path.mkdir(0o000)
43
    with patch.object(
44
        sys,
45
        "argv",
46
        ["devenv", "python", "test-proj", "--scripts_path", str(scripts_path)],
47
    ):
48
        with pytest.raises(PermissionError):
49
            main(parse_args())
50
    # add all permissions back so the directory can be cleaned up
51
    scripts_path.chmod(0o777)
52