@@ -670,21 +670,58 @@ def test_open_with_path_like_object(self):
670
670
@unittest .skipIf (sys .platform == "darwin" , "skipped on macOS" )
671
671
@unittest .skipUnless (TESTFN_UNDECODABLE , "only works if there are undecodable paths" )
672
672
def test_open_with_undecodable_path (self ):
673
- self .addCleanup (unlink , TESTFN_UNDECODABLE )
674
673
path = TESTFN_UNDECODABLE
675
- with managed_connect (path ) as cx :
674
+ self .addCleanup (unlink , path )
675
+ with managed_connect (path , in_mem = True ) as cx :
676
676
self .assertTrue (os .path .exists (path ))
677
677
cx .execute (self ._sql )
678
678
679
679
def test_open_uri (self ):
680
- with managed_connect (TESTFN ) as cx :
680
+ path = TESTFN
681
+ uri = "file:" + urllib .parse .quote (os .fsencode (path ))
682
+ self .assertFalse (os .path .exists (path ))
683
+ with managed_connect (uri , uri = True ) as cx :
684
+ self .assertTrue (os .path .exists (path ))
681
685
cx .execute (self ._sql )
682
- with managed_connect (f"file:{ TESTFN } " , uri = True ) as cx :
686
+
687
+ def test_open_unquoted_uri (self ):
688
+ path = TESTFN
689
+ uri = "file:" + path
690
+ self .assertFalse (os .path .exists (path ))
691
+ with managed_connect (uri , uri = True ) as cx :
692
+ self .assertTrue (os .path .exists (path ))
683
693
cx .execute (self ._sql )
694
+
695
+ def test_open_uri_readonly (self ):
696
+ path = TESTFN
697
+ self .addCleanup (unlink , path )
698
+ uri = "file:" + urllib .parse .quote (os .fsencode (path )) + "?mode=ro"
699
+ self .assertFalse (os .path .exists (path ))
700
+ # Cannot create new DB
684
701
with self .assertRaises (sqlite .OperationalError ):
685
- with managed_connect (f"file:{ TESTFN } ?mode=ro" , uri = True ) as cx :
702
+ sqlite .connect (uri , uri = True )
703
+ self .assertFalse (os .path .exists (path ))
704
+ sqlite .connect (path ).close ()
705
+ self .assertTrue (os .path .exists (path ))
706
+ # Cannot modify new DB
707
+ with managed_connect (uri , uri = True ) as cx :
708
+ with self .assertRaises (sqlite .OperationalError ):
686
709
cx .execute (self ._sql )
687
710
711
+ @unittest .skipIf (sys .platform == "win32" , "skipped on Windows" )
712
+ @unittest .skipIf (sys .platform == "darwin" , "skipped on macOS" )
713
+ @unittest .skipUnless (TESTFN_UNDECODABLE , "only works if there are undecodable paths" )
714
+ def test_open_undecodable_uri (self ):
715
+ path = TESTFN_UNDECODABLE
716
+ uri = "file:" + urllib .parse .quote (path )
717
+ self .assertFalse (os .path .exists (path ))
718
+ try :
719
+ with managed_connect (uri , uri = True , in_mem = True ) as cx :
720
+ self .assertTrue (os .path .exists (path ))
721
+ cx .execute (self ._sql )
722
+ finally :
723
+ unlink (path )
724
+
688
725
def test_factory_database_arg (self ):
689
726
def factory (database , * args , ** kwargs ):
690
727
nonlocal database_arg
0 commit comments