From 667a85aa46bee45d100a0c2bf7bc81e58786cdef Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sun, 19 Feb 2023 17:56:26 -0600 Subject: [PATCH] add a basic learn/retrieve test since I broke it a while back --- tests/fixtures/markov_fixture.json | 19 +++++++++++++++++++ tests/test_markov_lib.py | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/fixtures/markov_fixture.json create mode 100644 tests/test_markov_lib.py diff --git a/tests/fixtures/markov_fixture.json b/tests/fixtures/markov_fixture.json new file mode 100644 index 0000000..003b5b5 --- /dev/null +++ b/tests/fixtures/markov_fixture.json @@ -0,0 +1,19 @@ +[ +{ + "model": "markov.markovcontext", + "pk": 1, + "fields": { + "name": "#factory" + } +}, +{ + "model": "markov.markovtarget", + "pk": 1, + "fields": { + "name": "#factory", + "context": 1, + "channel": 1, + "chatter_chance": 0 + } +} +] diff --git a/tests/test_markov_lib.py b/tests/test_markov_lib.py new file mode 100644 index 0000000..e8f40b3 --- /dev/null +++ b/tests/test_markov_lib.py @@ -0,0 +1,17 @@ +"""Test markov utility methods.""" +from django.test import TestCase + +from markov.lib import get_word_out_of_states, learn_line +from markov.models import MarkovContext, MarkovState + + +class MarkovLibTestCase(TestCase): + """Test library methods used by the Markov plugin.""" + + fixtures = ['tests/fixtures/irc_server_fixture.json', 'tests/fixtures/markov_fixture.json'] + + def test_learn_and_get(self): + """Test that we can learn some lines and get a word back.""" + learn_line("the elephant goes ERRRRRRRRRRRRR", MarkovContext.objects.get(pk=1)) + word = get_word_out_of_states(MarkovState.objects.all()) + self.assertIn(word, ['the', 'elephant', 'goes', 'ERRRRRRRRRRRRR', '__stop'])