Testers
coola.equality.testers ¶
Contain the testers to check if two objects are equal or not.
coola.equality.testers.BaseEqualityTester ¶
              Bases: ABC
Define the base class to implement an equality tester.
            coola.equality.testers.BaseEqualityTester.equal
  
      abstractmethod
  
¶
equal(
    actual: Any, expected: Any, config: EqualityConfig
) -> bool
Indicate if two objects are equal or not.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                actual
             | 
            
                  Any
             | 
            
               The actual input.  | 
            required | 
                expected
             | 
            
                  Any
             | 
            
               The expected input.  | 
            required | 
                config
             | 
            
                  EqualityConfig
             | 
            
               The equality configuration.  | 
            required | 
Returns:
| Type | Description | 
|---|---|
                  bool
             | 
            
               
  | 
          
Example usage:
>>> import numpy as np
>>> from coola.equality import EqualityConfig
>>> from coola.equality.testers import EqualityTester
>>> tester = EqualityTester()
>>> config = EqualityConfig(tester=tester)
>>> tester.equal([np.ones((2, 3)), np.zeros(2)], [np.ones((2, 3)), np.zeros(2)], config)
True
>>> tester.equal([np.ones((2, 3)), np.ones(2)], [np.ones((2, 3)), np.zeros(2)], config)
False
coola.equality.testers.EqualityTester ¶
              Bases: BaseEqualityTester
Implement the default equality tester.
            coola.equality.testers.EqualityTester.add_comparator
  
      classmethod
  
¶
add_comparator(
    data_type: type,
    comparator: BaseEqualityComparator,
    exist_ok: bool = False,
) -> None
Add an equality comparator for a given data type.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                data_type
             | 
            
                  type
             | 
            
               The data type for this test.  | 
            required | 
                comparator
             | 
            
                  BaseEqualityComparator
             | 
            
               The comparator used to test the equality of the specified type.  | 
            required | 
                exist_ok
             | 
            
                  bool
             | 
            
               If   | 
            
                  False
             | 
          
Raises:
| Type | Description | 
|---|---|
                  RuntimeError
             | 
            
               if a comparator is already registered for the
data type and   | 
          
Example usage:
>>> from coola.equality.testers import EqualityTester
>>> from coola.equality.comparators import SequenceEqualityComparator
>>> EqualityTester.add_comparator(list, SequenceEqualityComparator(), exist_ok=True)
            coola.equality.testers.EqualityTester.find_comparator
  
      classmethod
  
¶
find_comparator(data_type: Any) -> BaseEqualityComparator
Find the equality comparator associated to an object.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                data_type
             | 
            
                  Any
             | 
            
               The data type to get.  | 
            required | 
Returns:
| Type | Description | 
|---|---|
                  BaseEqualityComparator
             | 
            
               The equality comparator associated to the data type.  | 
          
Example usage:
>>> from coola.equality.testers import EqualityTester
>>> EqualityTester.find_comparator(list)
SequenceEqualityComparator()
>>> EqualityTester.find_comparator(str)
DefaultEqualityComparator()
            coola.equality.testers.EqualityTester.has_comparator
  
      classmethod
  
¶
has_comparator(data_type: type) -> bool
Indicate if an equality comparator is registered for the given data type.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                data_type
             | 
            
                  type
             | 
            
               The data type to check.  | 
            required | 
Returns:
| Type | Description | 
|---|---|
                  bool
             | 
            
               
  | 
          
Example usage:
>>> from coola.equality.testers import EqualityTester
>>> EqualityTester.has_comparator(list)
True
>>> EqualityTester.has_comparator(str)
False
            coola.equality.testers.EqualityTester.local_copy
  
      classmethod
  
¶
local_copy() -> LocalEqualityTester
Return a copy of EqualityTester that can easily be
customized without changind EqualityTester.
Returns:
| Type | Description | 
|---|---|
                  LocalEqualityTester
             | 
            
               A "local" copy of   | 
          
Example usage:
>>> from coola.equality.testers import EqualityTester
>>> tester = EqualityTester.local_copy()
>>> tester
LocalEqualityTester(...)
coola.equality.testers.LocalEqualityTester ¶
              Bases: BaseEqualityTester
Implement an equality tester that can be easily customized.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                registry
             | 
            
                  dict[type, BaseEqualityComparator] | None
             | 
            
               The initial registry with the equality comparators.  | 
            
                  None
             | 
          
coola.equality.testers.LocalEqualityTester.add_comparator ¶
add_comparator(
    data_type: type,
    comparator: BaseEqualityComparator,
    exist_ok: bool = False,
) -> None
Add an equality comparator for a given data type.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                data_type
             | 
            
                  type
             | 
            
               The data type for this test.  | 
            required | 
                comparator
             | 
            
                  BaseEqualityComparator
             | 
            
               The comparator used to test the equality of the specified type.  | 
            required | 
                exist_ok
             | 
            
                  bool
             | 
            
               If   | 
            
                  False
             | 
          
Raises:
| Type | Description | 
|---|---|
                  RuntimeError
             | 
            
               if an comparator is already registered for the
data type and   | 
          
Example usage:
>>> from coola.equality.testers import EqualityTester
>>> from coola.equality.comparators import DefaultEqualityComparator
>>> tester = EqualityTester.local_copy()
>>> tester.add_comparator(str, DefaultEqualityComparator())
>>> tester.add_comparator(str, DefaultEqualityComparator(), exist_ok=True)
coola.equality.testers.LocalEqualityTester.clone ¶
clone() -> LocalEqualityTester
Clones the current tester.
Returns:
| Type | Description | 
|---|---|
                  LocalEqualityTester
             | 
            
               A deep copy of the current tester.  | 
          
Example usage:
```pycon
from coola.equality.testers import EqualityTester tester = EqualityTester.local_copy() tester_cloned = tester.clone()
```
coola.equality.testers.LocalEqualityTester.find_comparator ¶
find_comparator(data_type: Any) -> BaseEqualityComparator
Find the equality comparator associated to an object.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                data_type
             | 
            
                  Any
             | 
            
               The data type to get.  | 
            required | 
Returns:
| Type | Description | 
|---|---|
                  BaseEqualityComparator
             | 
            
               The equality comparator associated to the data type.  | 
          
Example usage:
>>> from coola.equality.testers import EqualityTester
>>> tester = EqualityTester.local_copy()
>>> tester.find_comparator(list)
SequenceEqualityComparator()
>>> tester.find_comparator(str)
DefaultEqualityComparator()
coola.equality.testers.LocalEqualityTester.has_comparator ¶
has_comparator(data_type: type) -> bool
Indicate if an equality comparator is registered for the given data type.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
                data_type
             | 
            
                  type
             | 
            
               The data type to check.  | 
            required | 
Returns:
| Type | Description | 
|---|---|
                  bool
             | 
            
               
  | 
          
Example usage:
>>> from coola.equality.testers import EqualityTester
>>> tester = EqualityTester.local_copy()
>>> tester.has_comparator(list)
True
>>> tester.has_comparator(str)
False