Compare commits

...

2 Commits

3 changed files with 47 additions and 0 deletions

View File

@ -18,6 +18,17 @@ class Command(BaseCommand):
bridge_states = context.states.filter(k1=MarkovState._start1, k2=MarkovState._start2,
v__regex=r'<.*>')
self._chain_remover(context, bridge_states)
# get states that look like mentions
for target in context.markovtarget_set.all():
if target.channel.server.additional_addressed_nicks:
all_nicks = '|'.join(target.channel.server.additional_addressed_nicks.split('\n') +
[target.channel.server.nickname])
else:
all_nicks = target.channel.server.nickname
mention_regex = r'^(({nicks})[:,]|@({nicks}))$'.format(nicks=all_nicks)
mention_states = context.states.filter(k1=MarkovState._start1, k2=MarkovState._start2,
v__regex=mention_regex)
self._chain_remover(context, mention_states)
def _chain_remover(self, context, start_states):
"""Remove a given k from markov states, deleting the found states after rebuilding subsequent states.

19
tests/fixtures/markov_fixture.json vendored Normal file
View File

@ -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
}
}
]

17
tests/test_markov_lib.py Normal file
View File

@ -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'])