Add unit testing capabilities and basic tests for check_for_usbdevice
[grml2usb.git] / test / grml2usb_test.py
1 """
2 grml2usb basic pytests
3 ~~~~~~~~~~~~~~~~~~~~~~
4
5 This script contains basic "unit" tests, implemented for and executed with pytest.
6
7 Requirements:
8 pytest (pip install pytest)
9
10 Runwith:
11 <project root>$ pytest [-m {basic}]
12
13 :copyright: (c) 2020 by Manuel Rom <roma@synpro.solutions>
14 :license: GPL v2 or any later version
15 :bugreports: http://grml.org/bugs/
16 """
17
18
19 import importlib
20
21 import pytest
22
23 grml2usb = importlib.import_module("grml2usb", ".")
24
25
26 @pytest.mark.check_for_usbdevice
27 def test_extract_device_name():
28     """Assert, that 'extract_device_name' returns a device name for a given path"""
29     assert grml2usb.extract_device_name("/dev/sda") == "sda"
30     assert grml2usb.extract_device_name("/dev/sdb") == "sdb"
31     assert grml2usb.extract_device_name("/dev/sdb4") == "sdb"
32
33
34 @pytest.mark.check_for_usbdevice
35 def test_extract_device_name_invalid():
36     """Assert, that 'extract_device_name' raises an Error, when given an incorrect string"""
37     with pytest.raises(AttributeError):
38         assert grml2usb.extract_device_name("/dev")
39     with pytest.raises(AttributeError):
40         assert grml2usb.extract_device_name("foobar")