MCPcopy Create free account
hub / github.com/MearaY/StegaPy / TestCLI

Class TestCLI

tests/test_e2e.py:168–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166
167
168class TestCLI:
169 def test_embed_extract_lsb(self, tmp_path):
170 stego = tmp_path / "stego.png"
171 out_dir = tmp_path / "out"
172 out_dir.mkdir()
173
174 r = _cli("embed", "-i", str(IMG_PATH), "-m", str(MSG_SHORT),
175 "-o", str(stego), "--algo", "lsb")
176 assert r.returncode == 0, r.stderr
177
178 r = _cli("extract", "-i", str(stego), "-o", str(out_dir))
179 assert r.returncode == 0, r.stderr
180
181 extracted = out_dir / MSG_SHORT.name
182 assert extracted.exists()
183 assert extracted.read_bytes() == MSG_SHORT.read_bytes()
184
185 def test_embed_extract_randlsb(self, tmp_path):
186 stego = tmp_path / "stego.png"
187 out_dir = tmp_path / "out"
188 out_dir.mkdir()
189
190 r = _cli("embed", "-i", str(IMG_PATH), "-m", str(MSG_SHORT),
191 "-o", str(stego), "--algo", "randlsb", "--no-compress")
192 assert r.returncode == 0, r.stderr
193
194 r = _cli("extract", "-i", str(stego), "-o", str(out_dir), "--algo", "randlsb")
195 assert r.returncode == 0, r.stderr
196
197 assert (out_dir / MSG_SHORT.name).read_bytes() == MSG_SHORT.read_bytes()
198
199 def test_watermark_workflow(self, tmp_path):
200 sig = tmp_path / "sig.bin"
201 stego = tmp_path / "wm.png"
202
203 r = _cli("wm", "generate-sig", "-o", str(sig), "-p", "testpwd")
204 assert r.returncode == 0, r.stderr
205
206 r = _cli("wm", "embed", "-i", str(IMG_PATH), "-s", str(sig),
207 "-o", str(stego), "-p", "testpwd")
208 assert r.returncode == 0, r.stderr
209
210 r = _cli("wm", "verify", "-i", str(stego), "-s", str(sig), "-p", "testpwd")
211 assert r.returncode == 0, r.stderr
212 assert "水印有效" in r.stdout
213
214 def test_missing_file_exits_nonzero(self):
215 r = _cli("embed", "-i", "nonexistent.png", "-m", str(MSG_SHORT),
216 "-o", "/tmp/out.png")
217 assert r.returncode != 0
218
219 def test_help(self):
220 r = _cli("--help")
221 assert r.returncode == 0
222 assert "embed" in r.stdout

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected