File tree Expand file tree Collapse file tree 5 files changed +14
-9
lines changed
Filter options
roots/test-util-copyasset_overwrite Expand file tree Collapse file tree 5 files changed +14
-9
lines changed
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Bugs fixed
5
5
----------
6
6
7
7
* #12096: Warn when files are overwritten in the build directory.
8
- Patch by Adam Turner.
8
+ Patch by Adam Turner and Bénédikt Tran .
9
9
* #12620: Ensure that old-style object description options are respected.
10
10
Patch by Adam Turner.
11
11
* #12601, #12625: Support callable objects in :py:class: `~typing.Annotated ` type
Original file line number Diff line number Diff line change @@ -75,6 +75,8 @@ def copy_asset_file(source: str | os.PathLike[str], destination: str | os.PathLi
75
75
msg = ('Copying the rendered template %s to %s will overwrite data, '
76
76
'as a file already exists at the destination path '
77
77
'and the content does not match.' )
78
+ # See https://github.com/sphinx-doc/sphinx/pull/12627#issuecomment-2241144330
79
+ # for the rationale for logger.info().
78
80
logger .info (msg , os .fsdecode (source ), os .fsdecode (destination ),
79
81
type = 'misc' , subtype = 'copy_overwrite' )
80
82
Original file line number Diff line number Diff line change @@ -106,7 +106,12 @@ def copyfile(
106
106
msg = f'{ os .fsdecode (source )} does not exist'
107
107
raise FileNotFoundError (msg )
108
108
109
- if not (dest_exists := path .exists (dest )) or not filecmp .cmp (source , dest ):
109
+ if (
110
+ not (dest_exists := path .exists (dest )) or
111
+ # comparison must be done using shallow=False since
112
+ # two different files might have the same size
113
+ not filecmp .cmp (source , dest , shallow = False )
114
+ ):
110
115
if __overwrite_warning__ and dest_exists :
111
116
# sphinx.util.logging imports sphinx.util.osutil,
112
117
# so use a local import to avoid circular imports
Original file line number Diff line number Diff line change 6
6
def _copy_asset_overwrite_hook (app ):
7
7
css = app .outdir / '_static' / 'custom-styles.css'
8
8
# html_static_path is copied by default
9
- assert css .read_text () == '/* html_static_path */\n '
9
+ assert css .read_text () == '/* html_static_path */\n ' , 'invalid default text'
10
10
# warning generated by here
11
11
copy_asset (
12
12
Path (__file__ ).parent .joinpath ('myext_static' , 'custom-styles.css' ),
13
13
app .outdir / '_static' ,
14
14
)
15
15
# This demonstrates the overwriting
16
- assert css .read_text () == '/* extension styles */\n '
16
+ assert css .read_text () == '/* extension styles */\n ' , 'overwriting failed'
17
17
return []
18
18
19
19
Original file line number Diff line number Diff line change @@ -106,18 +106,16 @@ def excluded(path):
106
106
assert not (destdir / '_templates' / 'sidebar.html' ).exists ()
107
107
108
108
109
- @pytest .mark .xfail (reason = 'Filesystem chicanery(?)' )
110
109
@pytest .mark .sphinx ('html' , testroot = 'util-copyasset_overwrite' )
111
110
def test_copy_asset_overwrite (app ):
112
111
app .build ()
113
- warnings = strip_colors (app .warning .getvalue ())
114
112
src = app .srcdir / 'myext_static' / 'custom-styles.css'
115
113
dst = app .outdir / '_static' / 'custom-styles.css'
116
- assert warnings == (
117
- f'WARNING: Copying the source path { src } to { dst } will overwrite data, '
114
+ assert (
115
+ f'Copying the source path { src } to { dst } will overwrite data, '
118
116
'as a file already exists at the destination path '
119
117
'and the content does not match.\n '
120
- )
118
+ ) in strip_colors ( app . status . getvalue ())
121
119
122
120
123
121
def test_template_basename ():
You can’t perform that action at this time.
0 commit comments