Skip to content

Commit 8913102

Browse files
Remove hardcoded path (BugFix) (#2040)
* Remove hardcoded path * Removed hardcoded paths in software raid * using pathlib open function
1 parent 7c13717 commit 8913102

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

providers/base/tests/test_check_software_raid.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
import unittest
33
from unittest.mock import patch
44
import check_software_raid
5+
import pathlib
56

67

78
class TestCheckSoftwareRAID(unittest.TestCase):
89

910
def test_get_md_stat_intel_raid(self):
1011

1112
expected_data = [{"device": "md126", "mode": "raid0"}]
13+
test_dir = pathlib.Path(__file__).parent / "test_data"
1214
raid_data = check_software_raid.get_md_stat(
13-
"tests/test_data/mdstat_intel_rst.txt"
15+
test_dir / "mdstat_intel_rst.txt"
1416
)
1517
self.assertListEqual(raid_data, expected_data)
1618

@@ -20,15 +22,16 @@ def test_get_md_stat_multiple_raid(self):
2022
{"device": "md2", "mode": "raid1"},
2123
{"device": "md1", "mode": "raid0"},
2224
]
25+
test_dir = pathlib.Path(__file__).parent / "test_data"
2326
raid_data = check_software_raid.get_md_stat(
24-
"tests/test_data/mdstat_multiple_raid.txt"
27+
test_dir / "mdstat_multiple_raid.txt"
2528
)
2629
self.assertListEqual(raid_data, expected_data)
2730

2831
def test_get_md_stat_empty(self):
29-
32+
test_dir = pathlib.Path(__file__).parent / "test_data"
3033
raid_data = check_software_raid.get_md_stat(
31-
"tests/test_data/mdstat_none_raid.txt"
34+
test_dir / "mdstat_none_raid.txt"
3235
)
3336
self.assertListEqual(raid_data, [])
3437

providers/base/tests/test_gl_support.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from gl_support import *
1919
from unittest.mock import patch, MagicMock
2020
import unittest
21+
import pathlib
2122

2223

2324
class RemoveColorCode(unittest.TestCase):
@@ -28,16 +29,17 @@ class RemoveColorCode(unittest.TestCase):
2829
@patch("subprocess.run")
2930
def test_succ(self, mock_run):
3031
gs = GLSupport()
32+
test_dir = pathlib.Path(__file__).parent / "test_data"
3133

32-
SUCC = "tests/test_data/gl_support_succ.txt"
33-
SUCC_CHANGED = "tests/test_data/gl_support_succ_changed.txt"
34-
FAIL = "tests/test_data/gl_support_fail.txt"
35-
FAIL_CHANGED = "tests/test_data/gl_support_fail_changed.txt"
36-
with open(SUCC, "r") as s, open(SUCC_CHANGED, "r") as sc:
34+
SUCC = test_dir / "gl_support_succ.txt"
35+
SUCC_CHANGED = test_dir / "gl_support_succ_changed.txt"
36+
FAIL = test_dir / "gl_support_fail.txt"
37+
FAIL_CHANGED = test_dir / "gl_support_fail_changed.txt"
38+
with SUCC.open() as s, SUCC_CHANGED.open() as sc:
3739
rv = gs.remove_color_code(s.read())
3840
self.assertEqual(rv, sc.read())
3941

40-
with open(FAIL, "r") as f, open(FAIL_CHANGED, "r") as fc:
42+
with FAIL.open() as f, FAIL_CHANGED.open() as fc:
4143
rv = gs.remove_color_code(f.read())
4244
self.assertEqual(rv, fc.read())
4345

0 commit comments

Comments
 (0)