2020-10-17 15:08:45 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_which(caplog):
|
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
caplog.set_level(logging.DEBUG, logger="cryptoadvance.specter")
|
|
|
|
|
import cryptoadvance.specter.util.shell as helpers
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
helpers.which("some_non_existing_binary")
|
|
|
|
|
assert False, "Should raise an Exception"
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
assert (
|
|
|
|
|
helpers.which("date") == "/bin/date" or helpers.which("date") == "/usr/bin/date"
|
|
|
|
|
) # travis-CI has it on /bin/date
|
2021-03-26 12:21:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_last_lines(caplog):
|
|
|
|
|
from cryptoadvance.specter.util.shell import get_last_lines_from_file
|
|
|
|
|
|
|
|
|
|
lines = get_last_lines_from_file("LICENSE", 30)
|
|
|
|
|
assert lines[-2].startswith("OUT OF OR IN CONNECTION WITH THE SOFTWARE ")
|
2022-03-21 13:57:55 +01:00
|
|
|
|
|
|
|
|
|
2026-08-08 14:12:46 +02:00
|
|
|
def test_grep(tmp_path):
|
|
|
|
|
"""grep returns a (found, line)-tuple. Asserting on the tuple itself is
|
|
|
|
|
always truthy, so always assert on the first element!"""
|
2022-03-21 13:57:55 +01:00
|
|
|
from cryptoadvance.specter.util.shell import grep
|
|
|
|
|
|
2026-08-08 14:12:46 +02:00
|
|
|
some_file = tmp_path / "some_file.txt"
|
|
|
|
|
some_file.write_text('name = "cryptoadvance_specter"\nversion = "1.2.3"\n')
|
|
|
|
|
|
|
|
|
|
found, line = grep(str(some_file), 'name = "cryptoadvance_specter"')
|
|
|
|
|
assert found
|
|
|
|
|
assert line.strip() == 'name = "cryptoadvance_specter"'
|
|
|
|
|
|
|
|
|
|
found, line = grep(str(some_file), "does not exist")
|
|
|
|
|
assert not found
|
|
|
|
|
assert line is None
|