|
3 | 3 | import pytest
|
4 | 4 |
|
5 | 5 | import pathins.stringbuilder
|
| 6 | +from pathins.datastructures import Coordinate |
6 | 7 |
|
7 | 8 |
|
8 | 9 | def test_bold_text(monkeypatch):
|
@@ -273,3 +274,73 @@ def mock_isatty():
|
273 | 274 | f" with component 'A' transform: [[1.0, 0], [0, 1.0]]{os.linesep}"
|
274 | 275 | f" with component 'B' transform: [[1.0, 0], [0, 1.0]]"
|
275 | 276 | )
|
| 277 | + |
| 278 | + |
| 279 | +def test_segment_line_default(monkeypatch): |
| 280 | + # mock tty |
| 281 | + def mock_isatty(): |
| 282 | + return True |
| 283 | + |
| 284 | + # apply the monkeypatch for sys.stdout.isatty() |
| 285 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 286 | + |
| 287 | + coord1 = Coordinate(0, 0, True, False, False, False) |
| 288 | + coord2 = Coordinate(1, 1, True, False, False, False) |
| 289 | + res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=False) |
| 290 | + assert res == "(0,0) (1,1): \033[1;96mLINE\033[0m 1.00 units" |
| 291 | + |
| 292 | + |
| 293 | +def test_segment_line_with_coord1_startpoint_color(monkeypatch): |
| 294 | + # mock tty |
| 295 | + def mock_isatty(): |
| 296 | + return True |
| 297 | + |
| 298 | + # apply the monkeypatch for sys.stdout.isatty() |
| 299 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 300 | + |
| 301 | + coord1 = Coordinate(0, 0, True, True, False, False) |
| 302 | + coord2 = Coordinate(1, 1, True, False, False, False) |
| 303 | + res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=False) |
| 304 | + assert res == "\033[32m(0,0)\033[0m (1,1): \033[1;96mLINE\033[0m 1.00 units" |
| 305 | + |
| 306 | + |
| 307 | +def test_segment_line_with_coord2_startpoint_color(monkeypatch): |
| 308 | + # mock tty |
| 309 | + def mock_isatty(): |
| 310 | + return True |
| 311 | + |
| 312 | + # apply the monkeypatch for sys.stdout.isatty() |
| 313 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 314 | + |
| 315 | + coord1 = Coordinate(0, 0, True, False, False, False) |
| 316 | + coord2 = Coordinate(1, 1, True, True, False, False) |
| 317 | + res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=False) |
| 318 | + assert res == "(0,0) \033[32m(1,1)\033[0m: \033[1;96mLINE\033[0m 1.00 units" |
| 319 | + |
| 320 | + |
| 321 | +def test_segment_line_with_endpoint_color(monkeypatch): |
| 322 | + # mock tty |
| 323 | + def mock_isatty(): |
| 324 | + return True |
| 325 | + |
| 326 | + # apply the monkeypatch for sys.stdout.isatty() |
| 327 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 328 | + |
| 329 | + coord1 = Coordinate(0, 0, True, False, True, False) |
| 330 | + coord2 = Coordinate(1, 1, True, False, False, False) |
| 331 | + res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=False) |
| 332 | + assert res == "\033[31m(0,0)\033[0m (1,1): \033[1;96mLINE\033[0m 1.00 units" |
| 333 | + |
| 334 | + |
| 335 | +def test_segment_line_with_nocolor(monkeypatch): |
| 336 | + # mock tty |
| 337 | + def mock_isatty(): |
| 338 | + return True |
| 339 | + |
| 340 | + # apply the monkeypatch for sys.stdout.isatty() |
| 341 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 342 | + |
| 343 | + coord1 = Coordinate(0, 0, True, False, True, False) |
| 344 | + coord2 = Coordinate(1, 1, True, False, False, False) |
| 345 | + res = pathins.stringbuilder.segment_line(coord1, coord2, 1.0, nocolor=True) |
| 346 | + assert res == "(0,0) (1,1): LINE 1.00 units" |
0 commit comments