Exemple #1
0
def test_set_get_value2(tmpdir, sysexit, capsys):
    main("%s set header --key:=value" % tmpdir.join("foo.ini"))
    # print(tmpdir.join('foo.ini').read())
    main("%s get header key" % tmpdir.join("foo.ini"))
    sysexit.assert_called_with(0)
    out, err = capsys.readouterr()
    assert out.strip() == 'value'
Exemple #2
0
def test_help_command(tmpdir, sysexit, capsys):
    main("help values")
    sysexit.assert_called_with(0)
    out, err = capsys.readouterr()
    print('out:', repr(out))
    print('docstring', repr(dkconfig.Config.values.__doc__))
    assert dkconfig.Config.values.__doc__ in out
Exemple #3
0
def test_help(tmpdir, sysexit, capsys):
    main("help")
    sysexit.assert_called_with(0)
    out, err = capsys.readouterr()
    assert 'add_section' in out
    assert 'set' in out
    assert 'get' in out
    assert 'items' in out
    assert 'dos' in out
    assert 'bash' in out
    assert 'cat' in out
    assert 'values' in out
    assert 'write' in out
Exemple #4
0
def test_debug(tmpdir, sysexit, capsys):
    file = tmpdir.join("foo.ini")
    main("%s get header key -d" % file)
    sysexit.assert_called_with(1)
    out, err = capsys.readouterr()
    err = err.replace('\\', '').strip()
    file = str(file).replace('\\', '')
    # compare = """ARGS: Namespace(command='get', debug=True, filename=['%s']) ['header', 'key']""" % file
    # py39 = """ARGS: Namespace(filename=['%s'], command='get', debug=True) ['header', 'key']""" % file
    assert err.endswith(" ['header', 'key']")
    err = err[:-len(" ['header', 'key']")]
    assert err.startswith("ARGS: ")
    err = err[len("ARGS: "):]
    errdict = eval(
        err, {"Namespace": dict
              })  # should be valid Python by now, convert Namespace to dict
    assert errdict['command'] == 'get'
    assert errdict['debug'] is True
    assert errdict['filename'] == [file]
Exemple #5
0
def test_bash(tmpdir, sysexit, capsys):
    main("%s set header key value" % tmpdir.join("foo.ini"))
    main("%s bash" % tmpdir.join("foo.ini"))
    sysexit.assert_called_with(0)
    out, err = capsys.readouterr()
    assert out.strip() == 'export KEY="value"'
Exemple #6
0
def test_dos(tmpdir, sysexit, capsys):
    main("%s set header key value" % tmpdir.join("foo.ini"))
    main("%s dos" % tmpdir.join("foo.ini"))
    sysexit.assert_called_with(0)
    out, err = capsys.readouterr()
    assert out.strip() == 'set "KEY=value"'
Exemple #7
0
def test_create_file(tmpdir, sysexit):
    assert len(tmpdir.listdir()) == 0
    main("%s set header key value" % tmpdir.join("foo.ini"))
    print("DIR:", tmpdir.listdir())
    assert len(tmpdir.listdir()) == 1
    sysexit.assert_called_with(0)
Exemple #8
0
def test_file_error(tmpdir):
    amadir = tmpdir.join('i-am-a-dir.ini')
    os.makedirs(str(amadir))
    with pytest.raises(IOError):
        main("%s set header key value" % amadir)
Exemple #9
0
def test_add_duplicate_section(tmpdir, sysexit, capsys):
    main("%s set header key value" % tmpdir.join("foo.ini"))
    main("%s add_section header" % tmpdir.join("foo.ini"))
    sysexit.assert_called_with(0)
    out, err = capsys.readouterr()
    assert out.strip() == ""
Exemple #10
0
def test_get_missing(tmpdir, sysexit, capsys):
    main("%s set header key value" % tmpdir.join("foo.ini"))
    main("%s get header missing" % tmpdir.join("foo.ini"))
    sysexit.assert_called_with(1)
    out, err = capsys.readouterr()
    assert out.strip() == ""
Exemple #11
0
def test_setlist(tmpdir, sysexit, capsys):
    main("%s setlist header key a b c" % tmpdir.join("foo.ini"))
    main("%s get header key" % tmpdir.join("foo.ini"))
    sysexit.assert_called_with(0)
    out, err = capsys.readouterr()
    assert out.split() == 'a b c'.split()
Exemple #12
0
def test_noargs(tmpdir, sysexit, capsys):
    main("%s set header key value" % tmpdir.join("foo.ini"))
    main("%s" % tmpdir.join("foo.ini"))
    sysexit.assert_called_with(0)
    out, err = capsys.readouterr()
    assert out.strip() == '[header]\nkey = value'