File: test_autoinstall.py

package info (click to toggle)
labgrid 25.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,796 kB
  • sloc: python: 21,352; sh: 846; makefile: 35
file content (64 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pexpect


def test_autoinstall_help():
    with pexpect.spawn('python -m labgrid.autoinstall.main --help') as spawn:
        spawn.expect("usage")
        spawn.expect(pexpect.EOF)
        spawn.close()
        assert spawn.exitstatus == 0

def test_autoinstall_error_missing_autoinstall(tmpdir):
    c = tmpdir.join("config.yaml")
    c.write("""
    targets:
        test: {}
    """)
    with pexpect.spawn(f'python -m labgrid.autoinstall.main {c}') as spawn:
        spawn.expect("no 'autoinstall' section found")
        spawn.expect(pexpect.EOF)
        spawn.close()
        assert spawn.exitstatus == 1

def test_autoinstall_error_missing_handler(tmpdir):
    c = tmpdir.join("config.yaml")
    c.write("""
    autoinstall: |
        print("foo")
    """)
    with pexpect.spawn(f'python -m labgrid.autoinstall.main {c}') as spawn:
        spawn.expect("no 'handler' definition found")
        spawn.expect(pexpect.EOF)
        spawn.close()
        assert spawn.exitstatus == 1

def test_autoinstall_no_targets(tmpdir):
    c = tmpdir.join("config.yaml")
    c.write("""
    autoinstall:
        handler: |
            print("handler-test-output")
    """)
    with pexpect.spawn(f'python -m labgrid.autoinstall.main {c}') as spawn:
        spawn.expect("no targets found")
        spawn.expect(pexpect.EOF)
        spawn.close()
        assert spawn.exitstatus == 1

def test_autoinstall_simple(tmpdir):
    c = tmpdir.join("config.yaml")
    c.write("""
    targets:
        test1:
            resources: {}
            drivers: {}
    autoinstall:
        handler: |
            print("handler-test-output")
    """)
    with pexpect.spawn(f'python -m labgrid.autoinstall.main --once {c}') as spawn:
        spawn.expect("handler-test-output")
        spawn.expect(pexpect.EOF)
        spawn.close()
        assert spawn.exitstatus == 0