mirror of
				https://github.com/enpaul/peewee-plus.git
				synced 2025-11-04 01:08:38 +00:00 
			
		
		
		
	Add function for calculating sqlite batch size
Add default sqlite variable limit constant
This commit is contained in:
		
							
								
								
									
										45
									
								
								tests/test_calc_batch_size.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								tests/test_calc_batch_size.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
# pylint: disable=redefined-outer-name
 | 
			
		||||
# pylint: disable=missing-class-docstring
 | 
			
		||||
# pylint: disable=too-few-public-methods
 | 
			
		||||
# pylint: disable=unused-import
 | 
			
		||||
import peewee
 | 
			
		||||
 | 
			
		||||
import peewee_plus
 | 
			
		||||
from .fixtures import fakedb
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_sqlite(fakedb):
 | 
			
		||||
    """Test the calculation of batch sizes on SQLite"""
 | 
			
		||||
 | 
			
		||||
    class TestModel(peewee.Model):
 | 
			
		||||
        class Meta:
 | 
			
		||||
            database = fakedb
 | 
			
		||||
 | 
			
		||||
        data = peewee.IntegerField()
 | 
			
		||||
 | 
			
		||||
    models = [TestModel(item) for item in range(500)]
 | 
			
		||||
    assert (
 | 
			
		||||
        peewee_plus.calc_batch_size(models) <= peewee_plus.SQLITE_DEFAULT_VARIABLE_LIMIT
 | 
			
		||||
    )
 | 
			
		||||
    assert peewee_plus.calc_batch_size(models) < len(models)
 | 
			
		||||
 | 
			
		||||
    assert peewee_plus.calc_batch_size([]) == 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_non_sqlite():
 | 
			
		||||
    """Test the calculation of batch sizes on non-SQLite"""
 | 
			
		||||
 | 
			
		||||
    class TestModel(peewee.Model):
 | 
			
		||||
        class Meta:
 | 
			
		||||
            database = peewee.DatabaseProxy()
 | 
			
		||||
 | 
			
		||||
        data = peewee.IntegerField()
 | 
			
		||||
 | 
			
		||||
    # Three is just chosen as an arbitrary multiplier to ensure the value is larger than the
 | 
			
		||||
    # sqlite variable limit
 | 
			
		||||
    assert peewee_plus.calc_batch_size(
 | 
			
		||||
        [
 | 
			
		||||
            TestModel(item)
 | 
			
		||||
            for item in range(peewee_plus.SQLITE_DEFAULT_VARIABLE_LIMIT * 3)
 | 
			
		||||
        ]
 | 
			
		||||
    ) == (peewee_plus.SQLITE_DEFAULT_VARIABLE_LIMIT * 3)
 | 
			
		||||
		Reference in New Issue
	
	Block a user