sphinx-cmd 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sphinx-cmd
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Command-line tools for Sphinx documentation management
5
5
  Author-email: Jared Dillard <jared.dillard@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/jdillard/sphinx-cmd
@@ -52,6 +52,32 @@ sphinx-cmd rm path/to/docs
52
52
  sphinx-cmd rm path/to/docs --dry-run
53
53
  ```
54
54
 
55
+ ### `sphinx-cmd mv`
56
+
57
+ Move/rename .rst files and automatically update all references to them.
58
+
59
+ ```bash
60
+ # Move and update all references
61
+ sphinx-cmd mv old-file.rst new-file.rst
62
+
63
+ # Move to a different directory
64
+ sphinx-cmd mv chapter1.rst topics/chapter1.rst
65
+
66
+ # Preview the move without making changes
67
+ sphinx-cmd mv old-file.rst new-file.rst --dry-run
68
+
69
+ # Move without updating references
70
+ sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
71
+ ```
72
+
73
+ #### Features
74
+
75
+ - Automatically updates `toctree` entries
76
+ - Updates `:doc:` references
77
+ - Updates `include` and `literalinclude` directives
78
+ - Handles relative paths correctly
79
+ - Preserves file relationships
80
+
55
81
  ## Development
56
82
 
57
83
  ```bash
@@ -73,6 +99,7 @@ mypy sphinx_cmd
73
99
  # Test the command
74
100
  sphinx-cmd --help
75
101
  sphinx-cmd rm --help
102
+ sphinx-cmd mv --help
76
103
  ```
77
104
 
78
105
  ## Adding New Commands
@@ -24,6 +24,32 @@ sphinx-cmd rm path/to/docs
24
24
  sphinx-cmd rm path/to/docs --dry-run
25
25
  ```
26
26
 
27
+ ### `sphinx-cmd mv`
28
+
29
+ Move/rename .rst files and automatically update all references to them.
30
+
31
+ ```bash
32
+ # Move and update all references
33
+ sphinx-cmd mv old-file.rst new-file.rst
34
+
35
+ # Move to a different directory
36
+ sphinx-cmd mv chapter1.rst topics/chapter1.rst
37
+
38
+ # Preview the move without making changes
39
+ sphinx-cmd mv old-file.rst new-file.rst --dry-run
40
+
41
+ # Move without updating references
42
+ sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
43
+ ```
44
+
45
+ #### Features
46
+
47
+ - Automatically updates `toctree` entries
48
+ - Updates `:doc:` references
49
+ - Updates `include` and `literalinclude` directives
50
+ - Handles relative paths correctly
51
+ - Preserves file relationships
52
+
27
53
  ## Development
28
54
 
29
55
  ```bash
@@ -45,6 +71,7 @@ mypy sphinx_cmd
45
71
  # Test the command
46
72
  sphinx-cmd --help
47
73
  sphinx-cmd rm --help
74
+ sphinx-cmd mv --help
48
75
  ```
49
76
 
50
77
  ## Adding New Commands
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sphinx-cmd"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  authors = [
9
9
  {name = "Jared Dillard", email = "jared.dillard@gmail.com"},
10
10
  ]
@@ -6,8 +6,6 @@ Main CLI entry point for sphinx-cmd with subcommands.
6
6
  import argparse
7
7
  import sys
8
8
 
9
- from sphinx_cmd.commands import rm
10
-
11
9
 
12
10
  def create_parser():
13
11
  """Create the main argument parser with subcommands."""
@@ -37,7 +35,26 @@ def create_parser():
37
35
  action="store_true",
38
36
  help="Preview deletions without removing files",
39
37
  )
40
- rm_parser.set_defaults(func=rm.execute)
38
+ rm_parser.set_defaults(command_name="rm")
39
+
40
+ # Add 'mv' subcommand
41
+ mv_parser = subparsers.add_parser(
42
+ "mv", help="Move/rename .rst files and update references"
43
+ )
44
+ mv_parser.add_argument("source", help="Source file to move")
45
+ mv_parser.add_argument("destination", help="Destination file or directory")
46
+ mv_parser.add_argument(
47
+ "-n",
48
+ "--dry-run",
49
+ action="store_true",
50
+ help="Preview move without actually moving files",
51
+ )
52
+ mv_parser.add_argument(
53
+ "--no-update-refs",
54
+ action="store_true",
55
+ help="Do not update references to the moved file",
56
+ )
57
+ mv_parser.set_defaults(command_name="mv")
41
58
 
42
59
  return parser
43
60
 
@@ -48,13 +65,23 @@ def main():
48
65
  args = parser.parse_args()
49
66
 
50
67
  # If no command is provided, show help
51
- if not hasattr(args, "func"):
68
+ if not hasattr(args, "command_name"):
52
69
  parser.print_help()
53
70
  sys.exit(1)
54
71
 
55
- # Execute the appropriate command
72
+ # Import and execute the appropriate command
56
73
  try:
57
- args.func(args)
74
+ if args.command_name == "rm":
75
+ from sphinx_cmd.commands.rm import execute
76
+
77
+ execute(args)
78
+ elif args.command_name == "mv":
79
+ from sphinx_cmd.commands.mv import execute
80
+
81
+ execute(args)
82
+ else:
83
+ print(f"Unknown command: {args.command_name}", file=sys.stderr)
84
+ sys.exit(1)
58
85
  except Exception as e:
59
86
  print(f"Error: {e}", file=sys.stderr)
60
87
  sys.exit(1)
@@ -0,0 +1,259 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Command to move/rename .rst files and update all references.
4
+ """
5
+
6
+ import re
7
+ import shutil
8
+ from collections import defaultdict
9
+ from pathlib import Path
10
+ from typing import Dict, List, Tuple
11
+
12
+ # Regex patterns for different types of references in reStructuredText
13
+ REFERENCE_PATTERNS = {
14
+ "toctree": re.compile(r"^\s*(\S+)\s*$", re.MULTILINE),
15
+ "include": re.compile(r"^\s*\.\.\s+include::\s+(.+)$", re.MULTILINE),
16
+ "literalinclude": re.compile(r"^\s*\.\.\s+literalinclude::\s+(.+)$", re.MULTILINE),
17
+ "code-block": re.compile(
18
+ r"^\s*\.\.\s+code-block::\s+\w+\s*\n\s*:name:\s+(.+)$", re.MULTILINE
19
+ ),
20
+ "reference": re.compile(r":doc:`([^`]+)`", re.MULTILINE),
21
+ "internal_link": re.compile(r"`([^<>`]+)\s+<([^>]+)>`__?", re.MULTILINE),
22
+ }
23
+
24
+ # Patterns that appear in toctree contexts
25
+ TOCTREE_PATTERN = re.compile(
26
+ r"^\s*\.\.\s+toctree::(.*?)(?=^\S|\Z)", re.DOTALL | re.MULTILINE
27
+ )
28
+
29
+
30
+ def find_all_rst_files(root_path: str) -> List[str]:
31
+ """Find all .rst files in the given directory tree."""
32
+ rst_files = []
33
+ root = Path(root_path)
34
+
35
+ if root.is_file() and root.suffix == ".rst":
36
+ return [str(root)]
37
+
38
+ for file_path in root.rglob("*.rst"):
39
+ rst_files.append(str(file_path))
40
+
41
+ return rst_files
42
+
43
+
44
+ def extract_references(file_path: str) -> Dict[str, List[str]]:
45
+ """Extract all file references from an .rst file."""
46
+ references = defaultdict(list)
47
+
48
+ with open(file_path, "r", encoding="utf-8") as f:
49
+ content = f.read()
50
+
51
+ # Find toctree entries
52
+ toctree_matches = TOCTREE_PATTERN.findall(content)
53
+ for toctree_content in toctree_matches:
54
+ # Extract file references from toctree
55
+ lines = toctree_content.split("\n")
56
+ for line in lines:
57
+ line = line.strip()
58
+ if line and not line.startswith(":"): # Skip options
59
+ # Handle both relative and absolute paths
60
+ ref_file = line.split()[0] if line.split() else ""
61
+ if ref_file:
62
+ references["toctree"].append(ref_file)
63
+
64
+ # Find other types of references
65
+ for ref_type, pattern in REFERENCE_PATTERNS.items():
66
+ if ref_type == "toctree":
67
+ continue # Already handled above
68
+
69
+ for match in pattern.findall(content):
70
+ if isinstance(match, tuple):
71
+ # For patterns with multiple groups, take the relevant one
72
+ ref_path = match[1] if ref_type == "internal_link" else match[0]
73
+ else:
74
+ ref_path = match
75
+ references[ref_type].append(ref_path)
76
+
77
+ return dict(references)
78
+
79
+
80
+ def find_files_referencing(
81
+ target_file: str, all_files: List[str]
82
+ ) -> List[Tuple[str, str]]:
83
+ """Find all files that reference the target file."""
84
+ referencing_files = []
85
+ target_path = Path(target_file)
86
+ target_stem = target_path.stem # filename without extension
87
+
88
+ for file_path in all_files:
89
+ if file_path == target_file:
90
+ continue
91
+
92
+ try:
93
+ references = extract_references(file_path)
94
+
95
+ for ref_type, ref_list in references.items():
96
+ for ref in ref_list:
97
+ # Normalize the reference path
98
+ ref_path = Path(ref)
99
+
100
+ # Check if this reference matches our target file
101
+ if (
102
+ ref_path.stem == target_stem
103
+ or ref == target_stem
104
+ or str(ref_path.with_suffix(".rst")) == target_file
105
+ ):
106
+ referencing_files.append((file_path, ref_type))
107
+ break
108
+ except Exception as e:
109
+ print(f"Warning: Could not analyze {file_path}: {e}")
110
+
111
+ return referencing_files
112
+
113
+
114
+ def update_references_in_file(file_path: str, old_ref: str, new_ref: str) -> bool:
115
+ """Update references to the moved file in a single file."""
116
+ old_path = Path(old_ref)
117
+ new_path = Path(new_ref)
118
+ old_stem = old_path.stem
119
+ new_stem = new_path.stem
120
+
121
+ try:
122
+ with open(file_path, "r", encoding="utf-8") as f:
123
+ content = f.read()
124
+
125
+ original_content = content
126
+
127
+ # Update different types of references
128
+ # 1. Toctree entries
129
+ content = re.sub(
130
+ rf"^\s*{re.escape(old_stem)}\s*$",
131
+ f" {new_stem}",
132
+ content,
133
+ flags=re.MULTILINE,
134
+ )
135
+
136
+ # 2. :doc: references
137
+ content = re.sub(
138
+ rf":doc:`{re.escape(old_stem)}`", f":doc:`{new_stem}`", content
139
+ )
140
+
141
+ # 3. Include directives
142
+ for directive in ["include", "literalinclude"]:
143
+ content = re.sub(
144
+ rf"^\s*\.\.\s+{directive}::\s+{re.escape(old_ref)}",
145
+ f".. {directive}:: {new_ref}",
146
+ content,
147
+ flags=re.MULTILINE,
148
+ )
149
+
150
+ # 4. Internal links
151
+ content = re.sub(
152
+ rf"`([^<>`]+)\s+<{re.escape(old_ref)}>`__?", rf"`\1 <{new_ref}>`_", content
153
+ )
154
+
155
+ # Write back if changes were made
156
+ if content != original_content:
157
+ with open(file_path, "w", encoding="utf-8") as f:
158
+ f.write(content)
159
+ return True
160
+
161
+ return False
162
+
163
+ except Exception as e:
164
+ print(f"Error updating references in {file_path}: {e}")
165
+ return False
166
+
167
+
168
+ def move_rst_file(
169
+ source: str, destination: str, update_references: bool = True, dry_run: bool = False
170
+ ) -> None:
171
+ """Move an RST file and optionally update all references to it."""
172
+ source_path = Path(source).resolve()
173
+ dest_path = Path(destination).resolve()
174
+
175
+ if not source_path.exists():
176
+ raise FileNotFoundError(f"Source file not found: {source}")
177
+
178
+ if not source_path.suffix == ".rst":
179
+ raise ValueError(f"Source must be an .rst file: {source}")
180
+
181
+ # If destination is a directory, use the same filename
182
+ if dest_path.is_dir():
183
+ dest_path = dest_path / source_path.name
184
+ elif not dest_path.suffix:
185
+ dest_path = dest_path.with_suffix(".rst")
186
+
187
+ # Get the relative paths for updating references
188
+ # Try to find a common root to make relative paths
189
+ try:
190
+ source_rel = source_path.relative_to(Path.cwd())
191
+ dest_rel = dest_path.relative_to(Path.cwd())
192
+ except ValueError:
193
+ # Fall back to absolute paths if no common root
194
+ source_rel = source_path
195
+ dest_rel = dest_path
196
+
197
+ print(f"Moving: {source_rel} -> {dest_rel}")
198
+
199
+ if not dry_run:
200
+ # Create destination directory if it doesn't exist
201
+ dest_path.parent.mkdir(parents=True, exist_ok=True)
202
+
203
+ # Move the file
204
+ shutil.move(str(source_path), str(dest_path))
205
+
206
+ if update_references:
207
+ # Find all .rst files that might reference this file
208
+ root_dir = Path.cwd() # Or use a smarter root detection
209
+ all_files = find_all_rst_files(str(root_dir))
210
+
211
+ # Find files that reference the moved file
212
+ referencing_files = find_files_referencing(str(source_rel), all_files)
213
+
214
+ if referencing_files:
215
+ print(f"\nUpdating references in {len(referencing_files)} file(s):")
216
+
217
+ for ref_file, ref_type in referencing_files:
218
+ print(f" - {ref_file} ({ref_type})")
219
+
220
+ if not dry_run:
221
+ source_stem = source_path.stem
222
+ dest_stem = dest_path.stem
223
+
224
+ # Update the references
225
+ updated = update_references_in_file(
226
+ ref_file, source_stem, dest_stem
227
+ )
228
+
229
+ if updated:
230
+ print(f" ✓ Updated references in {ref_file}")
231
+ else:
232
+ print(f" - No changes needed in {ref_file}")
233
+ else:
234
+ print("\nNo references to update.")
235
+
236
+
237
+ def execute(args):
238
+ """Execute the mv command."""
239
+ try:
240
+ # Determine if we should update references (default: yes)
241
+ update_refs = getattr(args, "no_update_refs", False)
242
+ update_references = not update_refs
243
+
244
+ # Perform the move
245
+ move_rst_file(
246
+ args.source,
247
+ args.destination,
248
+ update_references=update_references,
249
+ dry_run=getattr(args, "dry_run", False),
250
+ )
251
+
252
+ if not getattr(args, "dry_run", False):
253
+ print("\n✓ Move completed successfully!")
254
+ else:
255
+ print("\n[Dry run complete - no files were actually moved]")
256
+
257
+ except Exception as e:
258
+ print(f"Error: {e}")
259
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sphinx-cmd
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Command-line tools for Sphinx documentation management
5
5
  Author-email: Jared Dillard <jared.dillard@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/jdillard/sphinx-cmd
@@ -52,6 +52,32 @@ sphinx-cmd rm path/to/docs
52
52
  sphinx-cmd rm path/to/docs --dry-run
53
53
  ```
54
54
 
55
+ ### `sphinx-cmd mv`
56
+
57
+ Move/rename .rst files and automatically update all references to them.
58
+
59
+ ```bash
60
+ # Move and update all references
61
+ sphinx-cmd mv old-file.rst new-file.rst
62
+
63
+ # Move to a different directory
64
+ sphinx-cmd mv chapter1.rst topics/chapter1.rst
65
+
66
+ # Preview the move without making changes
67
+ sphinx-cmd mv old-file.rst new-file.rst --dry-run
68
+
69
+ # Move without updating references
70
+ sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
71
+ ```
72
+
73
+ #### Features
74
+
75
+ - Automatically updates `toctree` entries
76
+ - Updates `:doc:` references
77
+ - Updates `include` and `literalinclude` directives
78
+ - Handles relative paths correctly
79
+ - Preserves file relationships
80
+
55
81
  ## Development
56
82
 
57
83
  ```bash
@@ -73,6 +99,7 @@ mypy sphinx_cmd
73
99
  # Test the command
74
100
  sphinx-cmd --help
75
101
  sphinx-cmd rm --help
102
+ sphinx-cmd mv --help
76
103
  ```
77
104
 
78
105
  ## Adding New Commands
@@ -12,5 +12,9 @@ sphinx_cmd.egg-info/entry_points.txt
12
12
  sphinx_cmd.egg-info/requires.txt
13
13
  sphinx_cmd.egg-info/top_level.txt
14
14
  sphinx_cmd/commands/__init__.py
15
+ sphinx_cmd/commands/mv.py
15
16
  sphinx_cmd/commands/rm.py
17
+ tests/test_cli.py
18
+ tests/test_integration.py
19
+ tests/test_mv.py
16
20
  tests/test_rm.py
@@ -0,0 +1,43 @@
1
+ import sys
2
+ from unittest.mock import patch
3
+
4
+ import pytest
5
+
6
+ from sphinx_cmd.cli import create_parser, main
7
+
8
+
9
+ def test_cli_help():
10
+ """Test that the main CLI shows help information."""
11
+ parser = create_parser()
12
+ # This should not raise an exception
13
+ assert parser is not None
14
+ assert "sphinx-cmd" in parser.format_help()
15
+ assert "rm" in parser.format_help()
16
+ assert "mv" in parser.format_help()
17
+
18
+
19
+ def test_cli_no_command():
20
+ """Test CLI behavior when no command is provided."""
21
+ # Mock argv to simulate running with no arguments
22
+ with patch.object(sys, "argv", ["sphinx-cmd"]):
23
+ with pytest.raises(SystemExit) as excinfo:
24
+ main()
25
+ assert excinfo.value.code == 1
26
+
27
+
28
+ def test_cli_rm_help():
29
+ """Test that rm subcommand help works."""
30
+ with patch.object(sys, "argv", ["sphinx-cmd", "rm", "--help"]):
31
+ with pytest.raises(SystemExit) as excinfo:
32
+ main()
33
+ # Help should exit with code 0
34
+ assert excinfo.value.code == 0
35
+
36
+
37
+ def test_cli_mv_help():
38
+ """Test that mv subcommand help works."""
39
+ with patch.object(sys, "argv", ["sphinx-cmd", "mv", "--help"]):
40
+ with pytest.raises(SystemExit) as excinfo:
41
+ main()
42
+ # Help should exit with code 0
43
+ assert excinfo.value.code == 0
@@ -0,0 +1,48 @@
1
+ import os
2
+ import subprocess
3
+ import tempfile
4
+
5
+
6
+ def test_integration_rm_command():
7
+ """Integration test for the rm command through the CLI."""
8
+ with tempfile.TemporaryDirectory() as tmpdir:
9
+ # Create test files
10
+ rst_content = """
11
+ Test Page
12
+ =========
13
+
14
+ .. image:: test.png
15
+ """
16
+ with open(os.path.join(tmpdir, "test.rst"), "w") as f:
17
+ f.write(rst_content)
18
+
19
+ with open(os.path.join(tmpdir, "test.png"), "w") as f:
20
+ f.write("fake image")
21
+
22
+ # Run the command with dry-run
23
+ result = subprocess.run(
24
+ ["sphinx-cmd", "rm", tmpdir, "--dry-run"], capture_output=True, text=True
25
+ )
26
+
27
+ # Check that it executed successfully
28
+ assert result.returncode == 0
29
+ assert "[dry-run]" in result.stdout
30
+
31
+ # Verify files still exist after dry run
32
+ assert os.path.exists(os.path.join(tmpdir, "test.rst"))
33
+ assert os.path.exists(os.path.join(tmpdir, "test.png"))
34
+
35
+
36
+ def test_integration_help_commands():
37
+ """Test that all help commands work."""
38
+ commands = [
39
+ ["sphinx-cmd", "--help"],
40
+ ["sphinx-cmd", "rm", "--help"],
41
+ ["sphinx-cmd", "mv", "--help"],
42
+ ["sphinx-cmd", "--version"],
43
+ ]
44
+
45
+ for cmd in commands:
46
+ result = subprocess.run(cmd, capture_output=True, text=True)
47
+ # Help commands should exit with 0 or 1 (argparse help exits with 0)
48
+ assert result.returncode in [0, 1]
@@ -0,0 +1,158 @@
1
+ import os
2
+ import tempfile
3
+ from pathlib import Path
4
+ from unittest.mock import Mock
5
+
6
+ from sphinx_cmd.commands.mv import (
7
+ extract_references,
8
+ find_all_rst_files,
9
+ find_files_referencing,
10
+ update_references_in_file,
11
+ )
12
+
13
+
14
+ def test_find_rst_files():
15
+ """Test finding RST files in a directory tree."""
16
+ with tempfile.TemporaryDirectory() as tmpdir:
17
+ # Create test files
18
+ (Path(tmpdir) / "test1.rst").touch()
19
+ (Path(tmpdir) / "test2.txt").touch() # Not RST
20
+ subdir = Path(tmpdir) / "subdir"
21
+ subdir.mkdir()
22
+ (subdir / "test3.rst").touch()
23
+
24
+ files = find_all_rst_files(tmpdir)
25
+ rst_files = [Path(f).name for f in files]
26
+
27
+ assert "test1.rst" in rst_files
28
+ assert "test3.rst" in rst_files
29
+ assert "test2.txt" not in str(files)
30
+
31
+
32
+ def test_extract_references():
33
+ """Test extracting references from RST content."""
34
+ with tempfile.TemporaryDirectory() as tmpdir:
35
+ rst_file = Path(tmpdir) / "test.rst"
36
+ content = """
37
+ Test Document
38
+ =============
39
+
40
+ .. toctree::
41
+ :maxdepth: 2
42
+
43
+ intro
44
+ tutorial/basic
45
+ api
46
+
47
+ See :doc:`intro` for more information.
48
+
49
+ .. include:: snippets/example.rst
50
+
51
+ .. literalinclude:: code/example.py
52
+ """
53
+ rst_file.write_text(content)
54
+
55
+ refs = extract_references(str(rst_file))
56
+
57
+ assert "toctree" in refs
58
+ assert "intro" in refs["toctree"]
59
+ assert "tutorial/basic" in refs["toctree"]
60
+
61
+ assert "reference" in refs
62
+ assert "intro" in refs["reference"]
63
+
64
+ assert "include" in refs
65
+ assert "snippets/example.rst" in refs["include"]
66
+
67
+
68
+ def test_find_files_referencing():
69
+ """Test finding files that reference a target file."""
70
+ with tempfile.TemporaryDirectory() as tmpdir:
71
+ # Create target file
72
+ target = Path(tmpdir) / "target.rst"
73
+ target.write_text("Target content")
74
+
75
+ # Create referencing file
76
+ ref_file = Path(tmpdir) / "referencing.rst"
77
+ ref_content = """
78
+ .. toctree::
79
+
80
+ target
81
+
82
+ See :doc:`target` for details.
83
+ """
84
+ ref_file.write_text(ref_content)
85
+
86
+ # Create non-referencing file
87
+ other_file = Path(tmpdir) / "other.rst"
88
+ other_file.write_text("Other content")
89
+
90
+ all_files = [str(target), str(ref_file), str(other_file)]
91
+ refs = find_files_referencing(str(target), all_files)
92
+
93
+ # The function finds multiple types of references in the same file
94
+ # We expect 2 references: one from toctree and one from :doc:
95
+ assert len(refs) == 2
96
+ assert all(r[0] == str(ref_file) for r in refs)
97
+
98
+ # Check that we found both types of references
99
+ ref_types = {r[1] for r in refs}
100
+ assert "toctree" in ref_types
101
+ assert "reference" in ref_types
102
+
103
+
104
+ def test_update_references():
105
+ """Test updating references in a file."""
106
+ with tempfile.TemporaryDirectory() as tmpdir:
107
+ test_file = Path(tmpdir) / "test.rst"
108
+ content = """
109
+ .. toctree::
110
+
111
+ oldname
112
+
113
+ See :doc:`oldname` for details.
114
+ """
115
+ test_file.write_text(content)
116
+
117
+ updated = update_references_in_file(str(test_file), "oldname", "newname")
118
+
119
+ assert updated
120
+ new_content = test_file.read_text()
121
+ assert "newname" in new_content
122
+ assert "oldname" not in new_content
123
+
124
+
125
+ def test_move_command_dry_run():
126
+ """Test mv command in dry run mode."""
127
+ with tempfile.TemporaryDirectory() as tmpdir:
128
+ os.chdir(tmpdir)
129
+
130
+ # Create source file
131
+ source = Path("source.rst")
132
+ source.write_text("Source content")
133
+
134
+ # Create file that references it
135
+ ref_file = Path("index.rst")
136
+ ref_file.write_text(
137
+ """
138
+ .. toctree::
139
+
140
+ source
141
+ """
142
+ )
143
+
144
+ # Mock args
145
+ args = Mock()
146
+ args.source = "source.rst"
147
+ args.destination = "destination.rst"
148
+ args.dry_run = True
149
+ args.no_update_refs = False
150
+
151
+ # Run the move command
152
+ from sphinx_cmd.commands.mv import execute
153
+
154
+ execute(args)
155
+
156
+ # Verify source still exists (dry run)
157
+ assert source.exists()
158
+ assert not Path("destination.rst").exists()
@@ -10,7 +10,7 @@ from sphinx_cmd.commands.rm import (
10
10
  )
11
11
 
12
12
 
13
- def test_rm_command():
13
+ def test_rm_command_functionality():
14
14
  """Test the rm command functionality."""
15
15
  # Create a temporary directory structure
16
16
  with tempfile.TemporaryDirectory() as tmpdir:
@@ -61,9 +61,3 @@ Test Page
61
61
  assert os.path.exists(os.path.join(test_dir, "test.rst"))
62
62
  assert os.path.exists(os.path.join(test_dir, "image.png"))
63
63
  assert os.path.exists(os.path.join(test_dir, "figure.jpg"))
64
-
65
- print("All tests passed!")
66
-
67
-
68
- if __name__ == "__main__":
69
- test_rm_command()
File without changes
File without changes
File without changes