File: test_contracts.py

package info (click to toggle)
simplebayes 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 496 kB
  • sloc: python: 3,322; makefile: 165; sh: 24
file content (30 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from simplebayes.errors import (
    InvalidCategoryError,
    InvalidModelStateError,
    PayloadTooLargeError,
    PersistencePathError,
    SimpleBayesError,
    UnsupportedModelVersionError,
)
from simplebayes.models import CategorySummary, ClassificationResult


def test_classification_result_fields():
    result = ClassificationResult(category="spam", score=2.5)
    assert result.category == "spam"
    assert result.score == 2.5


def test_category_summary_fields():
    summary = CategorySummary(token_tally=3, prob_in_cat=0.75, prob_not_in_cat=0.25)
    assert summary.token_tally == 3
    assert summary.prob_in_cat == 0.75
    assert summary.prob_not_in_cat == 0.25


def test_error_hierarchy():
    assert issubclass(InvalidCategoryError, SimpleBayesError)
    assert issubclass(PersistencePathError, SimpleBayesError)
    assert issubclass(UnsupportedModelVersionError, SimpleBayesError)
    assert issubclass(InvalidModelStateError, SimpleBayesError)
    assert issubclass(PayloadTooLargeError, SimpleBayesError)