|
| 1 | +import pytest |
| 2 | + |
| 3 | +import pathins.stringbuilder |
| 4 | + |
| 5 | + |
| 6 | +def test_bold_text(monkeypatch): |
| 7 | + # mock tty |
| 8 | + def mock_isatty(): |
| 9 | + return True |
| 10 | + |
| 11 | + # apply the monkeypatch for sys.stdout.isatty() |
| 12 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 13 | + |
| 14 | + res = pathins.stringbuilder.bold_text("TEST") |
| 15 | + assert res == "\033[1mTEST\033[0m" |
| 16 | + |
| 17 | + |
| 18 | +def test_bold_text_nocolor(monkeypatch): |
| 19 | + # mock tty |
| 20 | + def mock_isatty(): |
| 21 | + return True |
| 22 | + |
| 23 | + # apply the monkeypatch for sys.stdout.isatty() |
| 24 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 25 | + |
| 26 | + res = pathins.stringbuilder.bold_text("TEST", nocolor=True) |
| 27 | + assert res == "TEST" |
| 28 | + |
| 29 | + |
| 30 | +def test_cyan_text(monkeypatch): |
| 31 | + # mock tty |
| 32 | + def mock_isatty(): |
| 33 | + return True |
| 34 | + |
| 35 | + # apply the monkeypatch for sys.stdout.isatty() |
| 36 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 37 | + |
| 38 | + res = pathins.stringbuilder.cyan_text("TEST") |
| 39 | + assert res == "\033[36mTEST\033[0m" |
| 40 | + |
| 41 | + |
| 42 | +def test_cyan_text_nocolor(monkeypatch): |
| 43 | + # mock tty |
| 44 | + def mock_isatty(): |
| 45 | + return True |
| 46 | + |
| 47 | + # apply the monkeypatch for sys.stdout.isatty() |
| 48 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 49 | + |
| 50 | + res = pathins.stringbuilder.cyan_text("TEST", nocolor=True) |
| 51 | + assert res == "TEST" |
| 52 | + |
| 53 | + |
| 54 | +def test_cyan_bright_text(monkeypatch): |
| 55 | + # mock tty |
| 56 | + def mock_isatty(): |
| 57 | + return True |
| 58 | + |
| 59 | + # apply the monkeypatch for sys.stdout.isatty() |
| 60 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 61 | + |
| 62 | + res = pathins.stringbuilder.cyan_bright_text("TEST") |
| 63 | + assert res == "\033[1;96mTEST\033[0m" |
| 64 | + |
| 65 | + |
| 66 | +def test_cyan_bright_text_nocolor(monkeypatch): |
| 67 | + # mock tty |
| 68 | + def mock_isatty(): |
| 69 | + return True |
| 70 | + |
| 71 | + # apply the monkeypatch for sys.stdout.isatty() |
| 72 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 73 | + |
| 74 | + res = pathins.stringbuilder.cyan_bright_text("TEST", nocolor=True) |
| 75 | + assert res == "TEST" |
| 76 | + |
| 77 | + |
| 78 | +def test_green_text(monkeypatch): |
| 79 | + # mock tty |
| 80 | + def mock_isatty(): |
| 81 | + return True |
| 82 | + |
| 83 | + # apply the monkeypatch for sys.stdout.isatty() |
| 84 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 85 | + |
| 86 | + res = pathins.stringbuilder.green_text("TEST") |
| 87 | + assert res == "\033[32mTEST\033[0m" |
| 88 | + |
| 89 | + |
| 90 | +def test_green_text_nocolor(monkeypatch): |
| 91 | + # mock tty |
| 92 | + def mock_isatty(): |
| 93 | + return True |
| 94 | + |
| 95 | + # apply the monkeypatch for sys.stdout.isatty() |
| 96 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 97 | + |
| 98 | + res = pathins.stringbuilder.green_text("TEST", nocolor=True) |
| 99 | + assert res == "TEST" |
| 100 | + |
| 101 | + |
| 102 | +def test_red_text(monkeypatch): |
| 103 | + # mock tty |
| 104 | + def mock_isatty(): |
| 105 | + return True |
| 106 | + |
| 107 | + # apply the monkeypatch for sys.stdout.isatty() |
| 108 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 109 | + |
| 110 | + res = pathins.stringbuilder.red_text("TEST") |
| 111 | + assert res == "\033[31mTEST\033[0m" |
| 112 | + |
| 113 | + |
| 114 | +def test_red_text_nocolor(monkeypatch): |
| 115 | + # mock tty |
| 116 | + def mock_isatty(): |
| 117 | + return True |
| 118 | + |
| 119 | + # apply the monkeypatch for sys.stdout.isatty() |
| 120 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 121 | + |
| 122 | + res = pathins.stringbuilder.red_text("TEST", nocolor=True) |
| 123 | + assert res == "TEST" |
| 124 | + |
| 125 | + |
| 126 | +def test_report_header(monkeypatch): |
| 127 | + # mock tty |
| 128 | + def mock_isatty(): |
| 129 | + return True |
| 130 | + |
| 131 | + # apply the monkeypatch for sys.stdout.isatty() |
| 132 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 133 | + |
| 134 | + res = pathins.stringbuilder.report_header("TEST") |
| 135 | + assert res == "-----\n\033[1;96mTEST\033[0m\n-----" |
| 136 | + |
| 137 | + |
| 138 | +def test_report_header_nocolor(monkeypatch): |
| 139 | + # mock tty |
| 140 | + def mock_isatty(): |
| 141 | + return True |
| 142 | + |
| 143 | + # apply the monkeypatch for sys.stdout.isatty() |
| 144 | + monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 145 | + |
| 146 | + res = pathins.stringbuilder.report_header("TEST", nocolor=True) |
| 147 | + assert res == "-----\nTEST\n-----" |
| 148 | + |
| 149 | + |
| 150 | +# def test_overlap_result_pass_default(monkeypatch): |
| 151 | +# # mock tty |
| 152 | +# def mock_isatty(): |
| 153 | +# return True |
| 154 | + |
| 155 | +# # apply the monkeypatch for sys.stdout.isatty() |
| 156 | +# monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 157 | + |
| 158 | +# res = pathins.stringbuilder.overlap_result("TEST", test_pass=True) |
| 159 | +# assert res == "[ \x1b[31mTEST\x1b[0m ]: Yes" |
| 160 | + |
| 161 | + |
| 162 | +# def test_overlap_result_pass_nocolor(monkeypatch): |
| 163 | +# # mock tty |
| 164 | +# def mock_isatty(): |
| 165 | +# return True |
| 166 | + |
| 167 | +# # apply the monkeypatch for sys.stdout.isatty() |
| 168 | +# monkeypatch.setattr(pathins.stringbuilder, "IS_A_TTY", mock_isatty) |
| 169 | + |
| 170 | +# res = pathins.stringbuilder.overlap_result("TEST", test_pass=True, nocolor=True) |
| 171 | +# assert res == "[ TEST ]: Yes" |
0 commit comments