Compare commits
	
		
			2 Commits
		
	
	
		
			8c1bd5bd71
			...
			2399b5e882
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2399b5e882 | |||
| ed538d6045 | 
| @ -1,4 +1,4 @@ | ||||
| # Generated by Django 3.2.18 on 2023-02-19 23:14 | ||||
| # Generated by Django 3.2.18 on 2023-02-20 00:09 | ||||
| 
 | ||||
| from django.db import migrations, models | ||||
| import django.db.models.deletion | ||||
|  | ||||
							
								
								
									
										24
									
								
								markov/migrations/0006_link_markovtarget_to_ircchannel.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								markov/migrations/0006_link_markovtarget_to_ircchannel.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| """Generated by Django 3.2.18 on 2023-02-19 23:15.""" | ||||
| from django.db import migrations | ||||
| 
 | ||||
| 
 | ||||
| def link_markovcontext_to_ircchannel(apps, schema_editor): | ||||
|     """Link the markov targets to a hopefully matching channel, by name.""" | ||||
|     IrcChannel = apps.get_model('ircbot', 'IrcChannel') | ||||
|     MarkovTarget = apps.get_model('markov', 'MarkovTarget') | ||||
|     for target in MarkovTarget.objects.all(): | ||||
|         channel = IrcChannel.objects.get(name=target.name) | ||||
|         target.channel = channel | ||||
|         target.save() | ||||
| 
 | ||||
| 
 | ||||
| class Migration(migrations.Migration): | ||||
|     """Populate the markov target to IRC channel link.""" | ||||
| 
 | ||||
|     dependencies = [ | ||||
|         ('markov', '0005_markovtarget_channel'), | ||||
|     ] | ||||
| 
 | ||||
|     operations = [ | ||||
|         migrations.RunPython(link_markovcontext_to_ircchannel) | ||||
|     ] | ||||
							
								
								
									
										20
									
								
								markov/migrations/0007_alter_markovtarget_channel.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								markov/migrations/0007_alter_markovtarget_channel.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| # Generated by Django 3.2.18 on 2023-02-20 00:11 | ||||
| 
 | ||||
| from django.db import migrations, models | ||||
| import django.db.models.deletion | ||||
| 
 | ||||
| 
 | ||||
| class Migration(migrations.Migration): | ||||
| 
 | ||||
|     dependencies = [ | ||||
|         ('ircbot', '0019_ircchannel_discord_bridge'), | ||||
|         ('markov', '0006_link_markovtarget_to_ircchannel'), | ||||
|     ] | ||||
| 
 | ||||
|     operations = [ | ||||
|         migrations.AlterField( | ||||
|             model_name='markovtarget', | ||||
|             name='channel', | ||||
|             field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ircbot.ircchannel'), | ||||
|         ), | ||||
|     ] | ||||
| @ -23,7 +23,7 @@ class MarkovTarget(models.Model): | ||||
| 
 | ||||
|     name = models.CharField(max_length=200, unique=True) | ||||
|     context = models.ForeignKey(MarkovContext, on_delete=models.CASCADE) | ||||
|     channel = models.ForeignKey(IrcChannel, null=True, on_delete=models.CASCADE) | ||||
|     channel = models.ForeignKey(IrcChannel, on_delete=models.CASCADE) | ||||
| 
 | ||||
|     chatter_chance = models.IntegerField(default=0) | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										17
									
								
								tests/test_markov_lib.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								tests/test_markov_lib.py
									
									
									
									
									
										Normal 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']) | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user