# evennia.contrib.rpg.traits.tests

Unit test module for Trait classes.

class `evennia.contrib.rpg.traits.tests.``TraitHandlerTest`(methodName='runTest')

  Bases: `evennia.contrib.rpg.traits.tests._TraitHandlerBase`

  Testing for TraitHandler

  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `test_add_trait`()
  `test_cache`()

    Cache should not be set until first get

  `test_setting`()

    Don’t allow setting stuff on traithandler

  `test_getting`()

    Test we are getting data from the dbstore

  `test_all`()

    Test all method

  `test_remove`()

    Test remove method

  `test_clear`()

    Test clear method

  `test_trait_db_connection`()

    Test that updating a trait property actually updates value in db

class `evennia.contrib.rpg.traits.tests.``TestTrait`(methodName='runTest')

  Bases: `evennia.contrib.rpg.traits.tests._TraitHandlerBase`

  Test the base Trait class

  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `test_init`()
  `test_validate_input__valid`()

    Test valid validation input

  `test_validate_input__fail`()

    Test failing validation

  `test_trait_getset`()

    Get-set-del operations on trait

  `test_repr`()

class `evennia.contrib.rpg.traits.tests.``TestTraitStatic`(methodName='runTest')

  Bases: `evennia.contrib.rpg.traits.tests._TraitHandlerBase`

  Test for static Traits

  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `test_init`()
  `test_value`()

    value is (base + mod) * mult

  `test_delete`()

    Deleting resets to default.

class `evennia.contrib.rpg.traits.tests.``TestTraitCounter`(methodName='runTest')

  Bases: `evennia.contrib.rpg.traits.tests._TraitHandlerBase`

  Test for counter- Traits

  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `test_init`()
  `test_value`()

    value is (current + mod) * mult, where current defaults to base

  `test_boundaries__minmax`()

    Test range

  `test_boundaries__bigmod`()

    add a big mod

  `test_boundaries__change_boundaries`()

    Change boundaries after base/mod change

  `test_boundaries__disable`()

    Disable and re-enable boundaries

  `test_boundaries__inverse`()

    Set inverse boundaries - limited by base

  `test_current`()

    Modifying current value

  `test_delete`()

    Deleting resets to default.

  `test_percentage`()

    Test percentage calculation

  `test_descs`()

    Test descriptions

class `evennia.contrib.rpg.traits.tests.``TestTraitCounterTimed`(methodName='runTest')

  Bases: `evennia.contrib.rpg.traits.tests._TraitHandlerBase`

  Test for trait with timer component

  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `test_timer_rate`(mock_time)

    Test time stepping

  `test_timer_ratetarget`(mock_time)

    test ratetarget

class `evennia.contrib.rpg.traits.tests.``TestTraitGauge`(methodName='runTest')

  Bases: `evennia.contrib.rpg.traits.tests._TraitHandlerBase`

  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `test_init`()
  `test_value`()

    value is current, where current defaults to base + mod

  `test_boundaries__minmax`()

    Test range

  `test_boundaries__bigmod`()

    add a big mod

  `test_boundaries__change_boundaries`()

    Change boundaries after current change

  `test_boundaries__disable`()

    Disable and re-enable boundary

  `test_boundaries__inverse`()

    Try to set reversed boundaries

  `test_current`()

    Modifying current value

  `test_delete`()

    Deleting resets to default.

  `test_percentage`()

    Test percentage calculation

  `test_descs`()

    Test descriptions

class `evennia.contrib.rpg.traits.tests.``TestTraitGaugeTimed`(methodName='runTest')

  Bases: `evennia.contrib.rpg.traits.tests._TraitHandlerBase`

  Test for trait with timer component

  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `test_timer_rate`(mock_time)

    Test time stepping

  `test_timer_ratetarget`(mock_time)

    test ratetarget

class `evennia.contrib.rpg.traits.tests.``TestNumericTraitOperators`(methodName='runTest')

  Bases: `evennia.utils.test_resources.BaseEvenniaTestCase`

  Test case for numeric magic method implementations.

  `setUp`()

    Hook method for setting up the test fixture before exercising it.

  `tearDown`()

    Hook method for deconstructing the test fixture after testing it.

  `test_pos_shortcut`()

    overridden unary + operator returns value property

  `test_add_traits`()

    test addition of Trait objects

  `test_sub_traits`()

    test subtraction of Trait objects

  `test_mul_traits`()

    test multiplication of Trait objects

  `test_floordiv`()

    test floor division of Trait objects

  `test_comparisons_traits`()

    test equality comparison between Trait objects

  `test_comparisons_numeric`()

    equality comparisons between Trait and numeric

class `evennia.contrib.rpg.traits.tests.``DummyCharacter`

  Bases: `evennia.contrib.rpg.traits.tests._MockObj`

  `strength`

    Allows for applying traits as individual properties directly on the parent class instead for properties on the .traits handler. So with this you could access data e.g. as character.hp.value instead of character.traits.hp.value. This still uses the traitshandler under the hood.

    Example:

        from evennia.utils import lazy_property
        from evennia.contrib.rpg.traits import TraitProperty

        class Character(DefaultCharacter):

            strength = TraitProperty(name="STR", trait_type="static", base=10, mod=2)
            hunting = TraitProperty("Hunting Skill", trait_type="counter",
                                    base=10, mod=1, max=100)
            health = TraitProperty(trait_type="gauge", min=0, base=100)

    Type

      Optional extra

  `hunting`

    Allows for applying traits as individual properties directly on the parent class instead for properties on the .traits handler. So with this you could access data e.g. as character.hp.value instead of character.traits.hp.value. This still uses the traitshandler under the hood.

    Example:

        from evennia.utils import lazy_property
        from evennia.contrib.rpg.traits import TraitProperty

        class Character(DefaultCharacter):

            strength = TraitProperty(name="STR", trait_type="static", base=10, mod=2)
            hunting = TraitProperty("Hunting Skill", trait_type="counter",
                                    base=10, mod=1, max=100)
            health = TraitProperty(trait_type="gauge", min=0, base=100)

    Type

      Optional extra

  `health`

    Allows for applying traits as individual properties directly on the parent class instead for properties on the .traits handler. So with this you could access data e.g. as character.hp.value instead of character.traits.hp.value. This still uses the traitshandler under the hood.

    Example:

        from evennia.utils import lazy_property
        from evennia.contrib.rpg.traits import TraitProperty

        class Character(DefaultCharacter):

            strength = TraitProperty(name="STR", trait_type="static", base=10, mod=2)
            hunting = TraitProperty("Hunting Skill", trait_type="counter",
                                    base=10, mod=1, max=100)
            health = TraitProperty(trait_type="gauge", min=0, base=100)

    Type

      Optional extra

class `evennia.contrib.rpg.traits.tests.``TestTraitFields`(methodName='runTest')

  Bases: `evennia.utils.test_resources.BaseEvenniaTestCase`

  Test the TraitField class.

  `test_traitfields`()

class `evennia.contrib.rpg.traits.tests.``TraitContribTestingChar`(id, db_key, db_typeclass_path, db_date_created, db_lock_storage, db_account, db_sessid, db_location, db_home, db_destination, db_cmdset_storage)

  Bases: `evennia.objects.objects.DefaultCharacter`

  `HP`

    Allows for applying traits as individual properties directly on the parent class instead for properties on the .traits handler. So with this you could access data e.g. as character.hp.value instead of character.traits.hp.value. This still uses the traitshandler under the hood.

    Example:

        from evennia.utils import lazy_property
        from evennia.contrib.rpg.traits import TraitProperty

        class Character(DefaultCharacter):

            strength = TraitProperty(name="STR", trait_type="static", base=10, mod=2)
            hunting = TraitProperty("Hunting Skill", trait_type="counter",
                                    base=10, mod=1, max=100)
            health = TraitProperty(trait_type="gauge", min=0, base=100)

    Type

      Optional extra

  exception `DoesNotExist`

    Bases: `evennia.objects.objects.DefaultCharacter.DoesNotExist`

  exception `MultipleObjectsReturned`

    Bases: `evennia.objects.objects.DefaultCharacter.MultipleObjectsReturned`

  `path` = 'evennia.contrib.rpg.traits.tests.TraitContribTestingChar'
  `typename` = 'TraitContribTestingChar'

class `evennia.contrib.rpg.traits.tests.``TraitPropertyTestCase`(methodName='runTest')

  Bases: `evennia.utils.test_resources.EvenniaTest`

  Test atomic updating.

  `character_typeclass`

    alias of `TraitContribTestingChar`

  `test_round1`()
  `test_round2`()