Esempio n. 1
0
def test_init_base():
    """
    armedcheckswitch.py: Test __init__() and its default parameters
    """
    s = ArmedCheckSwitch()
    assert s.is_switched() == False
    assert s.is_armed() == True
Esempio n. 2
0
def test_force():
    """
    lib/armedswitch.py: test force()
    """
    s = ArmedCheckSwitch()
    assert s.is_switched() == False
    assert s.switch() == True
    assert s.is_armed() == False
    assert s.switch() == False
    assert s.is_switched() == True
    s.force(False)
    assert s.is_switched() == False
Esempio n. 3
0
def test_arm():
    """
    armedcheckswitch.py: Test arm()
    """
    s = ArmedCheckSwitch()
    assert s.is_armed() == True
    assert s.switch() == True
    assert s.is_armed() == False
    s.arm()
    assert s.is_armed() == True
Esempio n. 4
0
def test_disarm():
    """
    armedcheckswitch.py: Test disarm()
    """
    s = ArmedCheckSwitch()
    assert s.is_armed() == True
    s.disarm()
    assert s.is_armed() == False
Esempio n. 5
0

def code_block_start_test(lines, index):
    """
    Tests to see if the line at the current index of lines indicates the
    start of a Markdown code block.

    :param lines: List of strings, with each entry corresponding to a single
        line in a text file
    :param index: The current line in lines
    :return: True if the current line indicates the start of a code block
    """
    return code_start.match(lines[index])


def code_block_end_test(lines, index):
    """
    Tests to see if the line at the current index of lines indicates the
    end of a Markdown code block.

    :param lines: List of strings, with each entry corresponding to a single
        line in a text file
    :param index: The current line in lines
    :return: True if the current line indicates the end of a code block
    """
    return code_end.match(lines[index])


code_block_switch = ArmedCheckSwitch(on_check=code_block_start_test,
                                     off_check=code_block_end_test)
Esempio n. 6
0
def test_switch_on_off():
    """
    armedcheckswitch.py: Test switch_on() and switch_off()
    """
    s = ArmedCheckSwitch(on_check=is_equal_to_one, off_check=is_equal_to_two)
    assert s.is_switched() == False

    assert s.switch_on(3) == False
    assert s.is_switched() == False

    assert s.switch_on(1) == True
    assert s.is_switched() == True

    assert s.switch_off(1) == False
    assert s.is_switched() == True

    # Should need to re-arm the switch to turn it off
    assert s.switch_off(2) == False
    assert s.is_switched() == True

    s.arm()
    assert s.switch_off(2) == True
    assert s.is_switched() == False
Esempio n. 7
0
def test_switch():
    """
    armedcheckswitch.py: Test switch()
    """
    s = ArmedCheckSwitch(on_check=is_equal_to_one, off_check=is_equal_to_two)
    assert s.is_switched() == False

    assert s.switch(4) == False
    assert s.is_switched() == False

    assert s.switch(1) == True
    assert s.is_switched() == True

    # Should need to re-arm before switching again
    assert s.switch(2) == False
    assert s.is_switched() == True

    s.arm()
    assert s.switch(2) == True
    assert s.is_switched() == False
Esempio n. 8
0
def test_init_params():
    """
    armedcheckswitch.py: Test __init__() with different parameters
    """
    s1 = ArmedCheckSwitch(switched=True, armed=False)
    assert s1.is_switched() == True
    assert s1.is_armed() == False

    s2 = ArmedCheckSwitch(switched=False, armed=False)
    assert s2.is_switched() == False
    assert s2.is_armed() == False

    s3 = ArmedCheckSwitch(armed=True, switched=True)
    assert s3.is_switched() == True
    assert s3.is_armed() == True

    s4 = ArmedCheckSwitch(armed=True, switched=False)
    assert s4.is_switched() == False
    assert s4.is_armed() == True