Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 3 | import _prep |
Pau Espin Pedrol | 6e0b6fb | 2020-05-25 19:49:29 +0200 | [diff] [blame] | 4 | |
| 5 | import time |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 6 | import os |
Pau Espin Pedrol | 6e0b6fb | 2020-05-25 19:49:29 +0200 | [diff] [blame] | 7 | |
Pau Espin Pedrol | e8bbcbf | 2020-04-10 19:51:31 +0200 | [diff] [blame] | 8 | from osmo_gsm_tester.core import util |
Pau Espin Pedrol | f574a46 | 2020-05-05 12:18:35 +0200 | [diff] [blame] | 9 | from osmo_gsm_tester.core.trial import Trial |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 10 | |
| 11 | workdir = util.get_tempdir() |
| 12 | |
| 13 | trials_dir = util.Dir(workdir) |
| 14 | |
| 15 | print('- make a few trials dirs') |
| 16 | print(trials_dir.mkdir('first')) |
| 17 | time.sleep(1) |
| 18 | print(trials_dir.mkdir('second')) |
| 19 | time.sleep(1) |
| 20 | print(trials_dir.mkdir('third')) |
| 21 | |
| 22 | print('- fetch trial dirs in order') |
| 23 | t = Trial.next(trials_dir) |
| 24 | print(t) |
| 25 | print(repr(sorted(t.dir.children()))) |
| 26 | print(Trial.next(trials_dir)) |
| 27 | print(Trial.next(trials_dir)) |
| 28 | |
| 29 | print('- no more trial dirs left') |
| 30 | print(repr(Trial.next(trials_dir))) |
| 31 | |
| 32 | print('- test checksum verification') |
| 33 | d = util.Dir('trial_test') |
| 34 | t = Trial(d.child('valid_checksums')) |
| 35 | t.verify() |
| 36 | |
| 37 | print('- detect wrong checksum') |
| 38 | t = Trial(d.child('invalid_checksum')) |
| 39 | try: |
| 40 | t.verify() |
| 41 | except RuntimeError as e: |
Pau Espin Pedrol | afa2fc3 | 2020-05-06 17:29:50 +0200 | [diff] [blame] | 42 | print('ok, got RuntimeError: %s' % str(e)) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 43 | |
| 44 | print('- detect missing file') |
| 45 | t = Trial(d.child('missing_file')) |
| 46 | try: |
| 47 | t.verify() |
| 48 | except RuntimeError as e: |
Pau Espin Pedrol | afa2fc3 | 2020-05-06 17:29:50 +0200 | [diff] [blame] | 49 | print('ok, got RuntimeError: %s' % str(e)) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 50 | |
Pau Espin Pedrol | 6e0b6fb | 2020-05-25 19:49:29 +0200 | [diff] [blame] | 51 | print('- Verify trials based on run_label') |
| 52 | d = util.Dir('trial_test') |
| 53 | t = Trial(d.child('run_label')) |
| 54 | t.verify() |
| 55 | inst = util.Dir(t.get_inst('sample', 'foobar')) |
| 56 | print('inst: ' + str(inst)) |
| 57 | with open(inst.child('file2'), 'r') as f: |
| 58 | print('content file2: %s' % f.read()) |
| 59 | inst = util.Dir( t.get_inst('sample')) |
| 60 | print('inst: ' + str(inst)) |
| 61 | with open(inst.child('file1'), 'r') as f: |
| 62 | print('content file1: %s' % f.read()) |
| 63 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 64 | # vim: expandtab tabstop=4 shiftwidth=4 |