@@ -320,6 +320,150 @@ def test_no_ttl(self, db, cf):
320320 assert value == b"value"
321321
322322
323+ class TestCloneColumnFamily :
324+ """Tests for column family clone operations."""
325+
326+ def test_clone_column_family (self , db , cf ):
327+ """Test cloning a column family with data."""
328+ with db .begin_txn () as txn :
329+ txn .put (cf , b"key1" , b"value1" )
330+ txn .put (cf , b"key2" , b"value2" )
331+ txn .commit ()
332+
333+ db .clone_column_family ("test_cf" , "cloned_cf" )
334+
335+ cloned = db .get_column_family ("cloned_cf" )
336+ assert cloned is not None
337+ assert cloned .name == "cloned_cf"
338+
339+ with db .begin_txn () as txn :
340+ assert txn .get (cloned , b"key1" ) == b"value1"
341+ assert txn .get (cloned , b"key2" ) == b"value2"
342+
343+ db .drop_column_family ("cloned_cf" )
344+
345+ def test_clone_independence (self , db , cf ):
346+ """Test that clone is independent from source."""
347+ with db .begin_txn () as txn :
348+ txn .put (cf , b"key1" , b"original" )
349+ txn .commit ()
350+
351+ db .clone_column_family ("test_cf" , "cloned_cf" )
352+ cloned = db .get_column_family ("cloned_cf" )
353+
354+ with db .begin_txn () as txn :
355+ txn .put (cf , b"key1" , b"modified" )
356+ txn .commit ()
357+
358+ with db .begin_txn () as txn :
359+ assert txn .get (cloned , b"key1" ) == b"original"
360+ assert txn .get (cf , b"key1" ) == b"modified"
361+
362+ db .drop_column_family ("cloned_cf" )
363+
364+ def test_clone_nonexistent_source (self , db ):
365+ """Test cloning a non-existent column family raises error."""
366+ with pytest .raises (tidesdb .TidesDBError ):
367+ db .clone_column_family ("nonexistent" , "cloned_cf" )
368+
369+ def test_clone_to_existing_name (self , db , cf ):
370+ """Test cloning to an already existing name raises error."""
371+ db .create_column_family ("existing_cf" )
372+ with pytest .raises (tidesdb .TidesDBError ):
373+ db .clone_column_family ("test_cf" , "existing_cf" )
374+ db .drop_column_family ("existing_cf" )
375+
376+ def test_clone_listed (self , db , cf ):
377+ """Test that cloned column family appears in list."""
378+ db .clone_column_family ("test_cf" , "cloned_cf" )
379+
380+ names = db .list_column_families ()
381+ assert "test_cf" in names
382+ assert "cloned_cf" in names
383+
384+ db .drop_column_family ("cloned_cf" )
385+
386+
387+ class TestTransactionReset :
388+ """Tests for transaction reset operations."""
389+
390+ def test_reset_after_commit (self , db , cf ):
391+ """Test resetting a transaction after commit."""
392+ txn = db .begin_txn ()
393+ txn .put (cf , b"key1" , b"value1" )
394+ txn .commit ()
395+
396+ txn .reset (tidesdb .IsolationLevel .READ_COMMITTED )
397+
398+ txn .put (cf , b"key2" , b"value2" )
399+ txn .commit ()
400+ txn .close ()
401+
402+ with db .begin_txn () as txn :
403+ assert txn .get (cf , b"key1" ) == b"value1"
404+ assert txn .get (cf , b"key2" ) == b"value2"
405+
406+ def test_reset_after_rollback (self , db , cf ):
407+ """Test resetting a transaction after rollback."""
408+ txn = db .begin_txn ()
409+ txn .put (cf , b"key1" , b"value1" )
410+ txn .rollback ()
411+
412+ txn .reset (tidesdb .IsolationLevel .READ_COMMITTED )
413+
414+ txn .put (cf , b"key2" , b"value2" )
415+ txn .commit ()
416+ txn .close ()
417+
418+ with db .begin_txn () as txn :
419+ with pytest .raises (tidesdb .TidesDBError ):
420+ txn .get (cf , b"key1" )
421+ assert txn .get (cf , b"key2" ) == b"value2"
422+
423+ def test_reset_with_different_isolation (self , db , cf ):
424+ """Test resetting with a different isolation level."""
425+ txn = db .begin_txn ()
426+ txn .put (cf , b"key1" , b"value1" )
427+ txn .commit ()
428+
429+ txn .reset (tidesdb .IsolationLevel .SERIALIZABLE )
430+
431+ txn .put (cf , b"key2" , b"value2" )
432+ txn .commit ()
433+ txn .close ()
434+
435+ with db .begin_txn () as txn :
436+ assert txn .get (cf , b"key1" ) == b"value1"
437+ assert txn .get (cf , b"key2" ) == b"value2"
438+
439+ def test_reset_reuse_loop (self , db , cf ):
440+ """Test resetting in a loop for batch processing."""
441+ txn = db .begin_txn ()
442+
443+ for i in range (5 ):
444+ txn .put (cf , f"batch_key_{ i } " .encode (), f"batch_value_{ i } " .encode ())
445+ txn .commit ()
446+ if i < 4 :
447+ txn .reset (tidesdb .IsolationLevel .READ_COMMITTED )
448+
449+ txn .close ()
450+
451+ with db .begin_txn () as txn :
452+ for i in range (5 ):
453+ value = txn .get (cf , f"batch_key_{ i } " .encode ())
454+ assert value == f"batch_value_{ i } " .encode ()
455+
456+ def test_reset_closed_transaction_raises (self , db , cf ):
457+ """Test that resetting a closed transaction raises error."""
458+ txn = db .begin_txn ()
459+ txn .put (cf , b"key1" , b"value1" )
460+ txn .commit ()
461+ txn .close ()
462+
463+ with pytest .raises (tidesdb .TidesDBError ):
464+ txn .reset (tidesdb .IsolationLevel .READ_COMMITTED )
465+
466+
323467class TestStats :
324468 """Tests for statistics operations."""
325469
0 commit comments