File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -3588,6 +3588,62 @@ fn add_script_without_metadata_table_with_shebang() -> Result<()> {
3588
3588
Ok ( ( ) )
3589
3589
}
3590
3590
3591
+ /// Add to a script with a metadata table and a shebang.
3592
+ #[ test]
3593
+ fn add_script_with_metadata_table_and_shebang ( ) -> Result < ( ) > {
3594
+ let context = TestContext :: new ( "3.12" ) ;
3595
+
3596
+ let script = context. temp_dir . child ( "script.py" ) ;
3597
+ script. write_str ( indoc ! { r#"
3598
+ #!/usr/bin/env python3
3599
+ # /// script
3600
+ # requires-python = ">=3.12"
3601
+ # dependencies = []
3602
+ # ///
3603
+ import requests
3604
+ from rich.pretty import pprint
3605
+
3606
+ resp = requests.get("https://peps.python.org/api/peps.json")
3607
+ data = resp.json()
3608
+ pprint([(k, v["title"]) for k, v in data.items()][:10])
3609
+ "# } ) ?;
3610
+
3611
+ uv_snapshot ! ( context. filters( ) , context. add( & [ "rich" , "requests<3" ] ) . arg( "--script" ) . arg( "script.py" ) , @r###"
3612
+ success: true
3613
+ exit_code: 0
3614
+ ----- stdout -----
3615
+
3616
+ ----- stderr -----
3617
+ Updated `script.py`
3618
+ "### ) ;
3619
+
3620
+ let script_content = fs_err:: read_to_string ( context. temp_dir . join ( "script.py" ) ) ?;
3621
+
3622
+ insta:: with_settings!( {
3623
+ filters => context. filters( ) ,
3624
+ } , {
3625
+ assert_snapshot!(
3626
+ script_content, @r###"
3627
+ #!/usr/bin/env python3
3628
+ # /// script
3629
+ # requires-python = ">=3.12"
3630
+ # dependencies = [
3631
+ # "rich",
3632
+ # "requests<3",
3633
+ # ]
3634
+ # ///
3635
+ import requests
3636
+ from rich.pretty import pprint
3637
+
3638
+ resp = requests.get("https://peps.python.org/api/peps.json")
3639
+ data = resp.json()
3640
+ pprint([(k, v["title"]) for k, v in data.items()][:10])
3641
+ "###
3642
+ ) ;
3643
+ } ) ;
3644
+ Ok ( ( ) )
3645
+ }
3646
+
3591
3647
/// Add to a script without a metadata table, but with a docstring.
3592
3648
#[ test]
3593
3649
fn add_script_without_metadata_table_with_docstring ( ) -> Result < ( ) > {
You can’t perform that action at this time.
0 commit comments