def test_load_nonexistent_cfg():
    # Supress stdout from exit_results
    old_stdout = sys.stdout
    sys.stdout = open(os.devnull, "w")
    try:
        aztp_os_selector.load_cfg('filename_that_does_not_exist')
    except SystemExit as e:
        pass
    finally:
        # resume stdout
        sys.stdout.close()
        sys.stdout = old_stdout
    assert str(e) == '1'
def test_load_cfg_bad_syntax():
    bad_yaml = '%%%%%%%%'
    os_sel = tempfile.NamedTemporaryFile(mode='w+b')
    os_sel.file.write(bad_yaml)
    os_sel.file.flush()

    # Supress stdout from exit_results
    old_stdout = sys.stdout
    sys.stdout = open(os.devnull, "w")
    try:
        aztp_os_selector.load_cfg(os_sel.name)
    except SystemExit as e:
        pass
    finally:
        # resume stdout
        sys.stdout.close()
        sys.stdout = old_stdout
    assert str(e) == '1'
def test_load_cfg():
    contents = {
        'default': {
            'regex_match': '3\.1\.[12]',
            'image': 'CumulusLinux-3.1.2-amd64.bin'
        }
    }
    osf = os_sel_file(contents=contents)
    cfg = aztp_os_selector.load_cfg(osf.name)
    assert cfg == contents