A collection of classes and commands for automated command line scripting using Python.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

83 lines
2.7 KiB

import pytest
from scripttease.exceptions import InvalidInput
from scripttease.lib.contexts import Context
from scripttease.lib.loaders.base import *
def test_load_variables():
vars = load_variables("nonexistent.ini")
assert len(vars) == 0
vars = load_variables("tests/examples/bad_variables.ini")
assert len(vars) == 0
vars = load_variables("tests/examples/variables.ini")
assert len(vars) == 5
vars = load_variables("tests/examples/variables.ini", env="testing")
assert len(vars) == 4
vars = load_variables("tests/examples/variables.ini", env="live")
assert len(vars) == 4
class TestBaseLoader(object):
def test_get_context(self):
c = Context()
c.add("testing", True)
o = BaseLoader("path/does/not/matter.txt", context=c)
assert 'testing' in o.get_context()
def test_get_key_value(self):
o = BaseLoader("path/does/not/matter.txt")
key, value = o._get_key_value("env", ["development", "testing"])
assert value == ["development", "testing"]
key, value = o._get_key_value("env", "testing")
assert value == ["testing"]
key, value = o._get_key_value("env", "development, testing")
assert value == ["development", "testing"]
key, value = o._get_key_value("func", "test_function")
assert key == "function"
assert value == "test_function"
key, value = o._get_key_value("groups", ["one", "two", "three"])
assert value == ["one", "two", "three"]
key, value = o._get_key_value("groups", "one, two, three")
assert value == ["one", "two", "three"]
key, value = o._get_key_value("items", ["one", "two", "three"])
assert value == ["one", "two", "three"]
key, value = o._get_key_value("items", "one, two, three")
assert value == ["one", "two", "three"]
key, value = o._get_key_value("tags", ["one", "two", "three"])
assert value == ["one", "two", "three"]
key, value = o._get_key_value("tags", "one, two, three")
assert value == ["one", "two", "three"]
key, value = o._get_key_value("testing", "1")
assert value == 1
def test_load(self):
o = BaseLoader("path/does/not/matter.txt")
with pytest.raises(NotImplementedError):
o.load()
def test_read_file(self):
c = Context()
c.add("domain_tld", "example_app")
o = BaseLoader("tests/examples/template_example.ini", context=c)
assert "example_app" in o.read_file()
c = Context()
c.add("domain_tld", "example_app")
o = BaseLoader("tests/examples/bad_template_example.ini", context=c)
assert o.read_file() is None