| 1 | import pexpect |
| 2 | |
| 3 | |
| 4 | def test_autoinstall_help(): |
| 5 | with pexpect.spawn("python -m labgrid.autoinstall.main --help") as spawn: |
| 6 | spawn.expect("usage") |
| 7 | spawn.expect(pexpect.EOF) |
| 8 | spawn.close() |
| 9 | assert spawn.exitstatus == 0 |
| 10 | |
| 11 | |
| 12 | def test_autoinstall_error_missing_autoinstall(tmpdir): |
| 13 | c = tmpdir.join("config.yaml") |
| 14 | c.write(""" |
| 15 | targets: |
| 16 | test: {} |
| 17 | """) |
| 18 | with pexpect.spawn(f"python -m labgrid.autoinstall.main {c}") as spawn: |
| 19 | spawn.expect("no 'autoinstall' section found") |
| 20 | spawn.expect(pexpect.EOF) |
| 21 | spawn.close() |
| 22 | assert spawn.exitstatus == 1 |
| 23 | |
| 24 | |
| 25 | def test_autoinstall_error_missing_handler(tmpdir): |
| 26 | c = tmpdir.join("config.yaml") |
| 27 | c.write(""" |
| 28 | autoinstall: | |
| 29 | print("foo") |
| 30 | """) |
| 31 | with pexpect.spawn(f"python -m labgrid.autoinstall.main {c}") as spawn: |
| 32 | spawn.expect("no 'handler' definition found") |
| 33 | spawn.expect(pexpect.EOF) |
| 34 | spawn.close() |
| 35 | assert spawn.exitstatus == 1 |
| 36 | |
| 37 | |
| 38 | def test_autoinstall_no_targets(tmpdir): |
| 39 | c = tmpdir.join("config.yaml") |
| 40 | c.write(""" |
| 41 | autoinstall: |
| 42 | handler: | |
| 43 | print("handler-test-output") |
| 44 | """) |
| 45 | with pexpect.spawn(f"python -m labgrid.autoinstall.main {c}") as spawn: |
| 46 | spawn.expect("no targets found") |
| 47 | spawn.expect(pexpect.EOF) |
| 48 | spawn.close() |
| 49 | assert spawn.exitstatus == 1 |
| 50 | |
| 51 | |
| 52 | def test_autoinstall_simple(tmpdir): |
| 53 | c = tmpdir.join("config.yaml") |
| 54 | c.write(""" |
| 55 | targets: |
| 56 | test1: |
| 57 | resources: {} |
| 58 | drivers: {} |
| 59 | autoinstall: |
| 60 | handler: | |
| 61 | print("handler-test-output") |
| 62 | """) |
| 63 | with pexpect.spawn(f"python -m labgrid.autoinstall.main --once {c}") as spawn: |
| 64 | spawn.expect("handler-test-output") |
| 65 | spawn.expect(pexpect.EOF) |
| 66 | spawn.close() |
| 67 | assert spawn.exitstatus == 0 |