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