Initial commit
This commit is contained in:
98
tests/test_dummy.py
Normal file
98
tests/test_dummy.py
Normal file
@@ -0,0 +1,98 @@
|
||||
import pytest
|
||||
|
||||
from myutils.Dummy import Dummy
|
||||
|
||||
|
||||
def test_i_can_call_any_method():
|
||||
"""Test that calling any non-existent method does not raise an error."""
|
||||
dummy = Dummy()
|
||||
dummy.any_method()
|
||||
dummy.some_random_function()
|
||||
dummy.whatever_i_want()
|
||||
|
||||
|
||||
def test_i_can_call_method_with_arguments():
|
||||
"""Test that methods can be called with positional and keyword arguments."""
|
||||
dummy = Dummy()
|
||||
dummy.method_with_args(1, 2, 3)
|
||||
dummy.method_with_kwargs(foo="bar", baz=123)
|
||||
dummy.method_with_both(1, 2, key="value", another=True)
|
||||
|
||||
|
||||
def test_i_can_access_any_attribute():
|
||||
"""Test that accessing any non-existent attribute returns a Dummy instance."""
|
||||
dummy = Dummy()
|
||||
result = dummy.any_attribute
|
||||
assert isinstance(result, Dummy)
|
||||
|
||||
result2 = dummy.another_property
|
||||
assert isinstance(result2, Dummy)
|
||||
|
||||
|
||||
def test_i_can_chain_attributes():
|
||||
"""Test that chaining multiple attributes works correctly."""
|
||||
dummy = Dummy()
|
||||
result = dummy.foo.bar.baz
|
||||
assert isinstance(result, Dummy)
|
||||
|
||||
result2 = dummy.level1.level2.level3.level4
|
||||
assert isinstance(result2, Dummy)
|
||||
|
||||
|
||||
def test_i_can_set_any_attribute():
|
||||
"""Test that setting any attribute does not raise an error."""
|
||||
dummy = Dummy()
|
||||
dummy.property = "value"
|
||||
dummy.number = 42
|
||||
dummy.nested = {"key": "value"}
|
||||
|
||||
|
||||
def test_method_call_returns_none():
|
||||
"""Test that calling a method returns None (no chaining)."""
|
||||
dummy = Dummy()
|
||||
result = dummy.some_method()
|
||||
assert result is None
|
||||
|
||||
result2 = dummy.another_method(1, 2, 3)
|
||||
assert result2 is None
|
||||
|
||||
|
||||
def test_dummy_evaluates_to_false():
|
||||
"""Test that Dummy evaluates to False in boolean context."""
|
||||
dummy = Dummy()
|
||||
assert not dummy
|
||||
assert bool(dummy) is False
|
||||
|
||||
if dummy:
|
||||
pytest.fail("Dummy should evaluate to False")
|
||||
|
||||
|
||||
def test_dummy_repr():
|
||||
"""Test the string representation of Dummy object."""
|
||||
dummy = Dummy()
|
||||
assert repr(dummy) == "<Dummy>"
|
||||
assert str(dummy) == "<Dummy>"
|
||||
|
||||
|
||||
def test_attribute_is_not_stored():
|
||||
"""Test that assigned attributes are not actually stored."""
|
||||
dummy = Dummy()
|
||||
dummy.stored_value = 123
|
||||
|
||||
# Accessing the attribute should return a new Dummy, not the stored value
|
||||
result = dummy.stored_value
|
||||
assert isinstance(result, Dummy)
|
||||
assert result is not 123
|
||||
|
||||
|
||||
def test_i_can_chain_and_call():
|
||||
"""Test that chaining attributes and then calling works correctly."""
|
||||
dummy = Dummy()
|
||||
result = dummy.foo.bar()
|
||||
assert result is None
|
||||
|
||||
result2 = dummy.level1.level2.level3()
|
||||
assert result2 is None
|
||||
|
||||
result3 = dummy.attr1.attr2.method(1, 2, key="value")
|
||||
assert result3 is None
|
||||
Reference in New Issue
Block a user