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