3 from ceph_volume.devices.simple import scan
6 class TestScan(object):
8 def test_main_spits_help_with_no_arguments(self, capsys):
10 stdout, stderr = capsys.readouterr()
11 assert 'Scan an OSD directory for files' in stdout
14 class TestGetContents(object):
16 def test_multiple_lines_are_left_as_is(self, tmpfile):
17 magic_file = tmpfile(contents='first\nsecond\n')
18 scanner = scan.Scan([])
19 assert scanner.get_contents(magic_file) == 'first\nsecond\n'
21 def test_extra_whitespace_gets_removed(self, tmpfile):
22 magic_file = tmpfile(contents='first ')
23 scanner = scan.Scan([])
24 assert scanner.get_contents(magic_file) == 'first'
26 def test_single_newline_values_are_trimmed(self, tmpfile):
27 magic_file = tmpfile(contents='first\n')
28 scanner = scan.Scan([])
29 assert scanner.get_contents(magic_file) == 'first'
32 class TestEtcPath(object):
34 def test_directory_is_valid(self, tmpdir):
36 scanner = scan.Scan([])
37 scanner._etc_path = path
38 assert scanner.etc_path == path
40 def test_directory_does_not_exist_gets_created(self, tmpdir):
41 path = os.path.join(str(tmpdir), 'subdir')
42 scanner = scan.Scan([])
43 scanner._etc_path = path
44 assert scanner.etc_path == path
45 assert os.path.isdir(path)
47 def test_complains_when_file(self, tmpfile):
49 scanner = scan.Scan([])
50 scanner._etc_path = path
51 with pytest.raises(RuntimeError):