Skip to content

Commit f116ae3

Browse files
More Testing. Tweaked To Support Python 2.7.18
1 parent 2663e86 commit f116ae3

File tree

9 files changed

+107
-58
lines changed

9 files changed

+107
-58
lines changed

examples/ex_local.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Basic example for accessing ZFS on local machine
2+
# Test requirements:
3+
# python-magic
24
import sys
35
import zfslib as zfs
46
from zfslib_ex_common import *
@@ -43,5 +45,7 @@ def main(argv):
4345

4446
if __name__ == '__main__':
4547
main(sys.argv[1:])
48+
sys.exit(0)
49+
4650

4751

examples/ex_other.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# See: https://github.com/JavaScriptDude/zfslib
2+
# Test requirements:
3+
# python-magic
24

35
import sys, magic, subprocess
46
from datetime import datetime, timedelta
@@ -65,10 +67,9 @@ def main(argv):
6567
c = snapshots[-1:][0].pool.connection
6668

6769

68-
ds_name_full = f"{pool_name}/{ds_name}"
6970

7071
# Print datasets creation date
71-
print(f"{ds_name_full} creation date: {ds.creation}")
72+
print("{} creation date: {}".format(ds.path, ds.creation))
7273

7374
# Grab Snapshots
7475
snapshots = ds.get_snapshots()
@@ -77,14 +78,14 @@ def main(argv):
7778
snap=snapshots[0]
7879

7980
# Get Snapshot Creation date
80-
print(f"{ds_name_full}@{snap.name} creation date: {ds.creation}")
81+
print("{} creation date: {}".format(snap.path, snap.creation))
8182

8283
# Read property from DataSet / Snapshot
83-
print(f"{ds_name_full}@{snap.name} usedsnap: {snap.get_property('usedsnap')}")
84-
84+
print("{} usedsnap: {}".format(snap.path, snap.get_property('usedsnap')))
8585

8686

8787
if __name__ == '__main__':
8888
main(sys.argv[1:])
89+
sys.exit(0)
8990

9091

examples/ex_remote.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Basic example for accessing ZFS on remote machine
2-
2+
# Test requirements:
3+
# python-magic
34
import sys
45
import zfslib as zfs
56
from zfslib_ex_common import *
@@ -56,5 +57,6 @@ def main(argv):
5657

5758
if __name__ == '__main__':
5859
main(sys.argv[1:])
60+
sys.exit(0)
5961

6062

examples/zfslib_ex_common.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1+
2+
# Test requirements:
3+
# python-magic
14
import sys, magic, subprocess
25
import zfslib as zfs
36

47
from datetime import datetime, timedelta
58

6-
def print_all_datasets(pool: zfs.Pool):
9+
def print_all_datasets(pool):
710
allds = pool.get_all_datasets(with_depth=True)
811
for (depth, ds) in allds:
912
print("{}: {} {} ({})".format(pool.name, ' .'*depth, ds.name, ds.dspath))
1013

1114

1215

13-
def print_all_datasets(pool: zfs.Pool):
16+
def print_all_datasets(pool):
1417
allds = pool.get_all_datasets(with_depth=True)
1518
for (depth, ds) in allds:
1619
print("{}: {} {} ({})".format(pool.name, ' .'*depth, ds.name, ds.dspath))
1720

1821

1922
# This can be very slow for large datasets. Its actually `zfs diff` thats the slow part
20-
def print_diffs_test(ds: zfs.Dataset, snapshots: list):
23+
def print_diffs_test(ds, snapshots):
2124
snap_last = None
2225
for i, snap in enumerate(snapshots):
2326

@@ -48,7 +51,7 @@ def print_diffs_test(ds: zfs.Dataset, snapshots: list):
4851

4952

5053

51-
def get_file_diff(diff:zfs.Diff):
54+
def get_file_diff(diff):
5255
if not diff.file_type == 'F':
5356
raise Exception('get_file_diff() is only available for files (file_type = F).')
5457
if not diff.chg_type == 'M':

tests/test_sync.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
@author: rudd-o
55
'''
6-
import unittest
6+
import unittest2
77
import zfslib as zfs
88
from zfslib_test_tools import *
99
import sync
@@ -15,7 +15,7 @@ def x(string):
1515
)
1616

1717

18-
class TestRecursiveReplicate(unittest.TestCase):
18+
class TestRecursiveReplicate(unittest2.TestCase):
1919

2020
maxDiff = None
2121

@@ -1075,7 +1075,7 @@ def test_replicates_complex_datasets(self):
10751075
self.assertEqual(expected_coalesced_recursivized,real_coalesced_recursivized)
10761076

10771077

1078-
class TestRecursiveClearObsolete(unittest.TestCase):
1078+
class TestRecursiveClearObsolete(unittest2.TestCase):
10791079

10801080
maxDiff = None
10811081

@@ -1270,4 +1270,5 @@ def test_destroys_all_datasets_recursively(self):
12701270

12711271
if __name__ == "__main__":
12721272
#import sys;sys.argv = ['', 'Test.testName']
1273-
unittest.main()
1273+
unittest2.main()
1274+
sys.exit(0)

tests/test_zfslib.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unittest
1+
import unittest2
22
from datetime import datetime, timedelta, date as dt_date
33
import zfslib as zfs
44
from zfslib_test_tools import *
@@ -20,7 +20,7 @@
2020
ps_nm = TestPoolSet()
2121
ps_nm.parse_zfs_r_output(zlist_data_nm, properties=props_nm)
2222

23-
class PoolSetTests(unittest.TestCase):
23+
class PoolSetTests(unittest2.TestCase):
2424

2525

2626
def test_pool_names(self):
@@ -480,7 +480,7 @@ def test_splitPath(self):
480480

481481

482482

483-
class Simplify_Tests(unittest.TestCase):
483+
class Simplify_Tests(unittest2.TestCase):
484484

485485
def test_simple(self):
486486
m = [
@@ -527,7 +527,7 @@ def test_with_strings(self):
527527
self.assertEqual(r1, r2)
528528

529529

530-
class Uniq_Tests(unittest.TestCase):
530+
class Uniq_Tests(unittest2.TestCase):
531531

532532
def test_identity(self):
533533
s = "abc"
@@ -557,4 +557,5 @@ def test_idfun(self):
557557

558558

559559
if __name__ == "__main__":
560-
unittest.main()
560+
unittest2.main()
561+
sys.exit(0)

tests/test_zfslib_online.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unittest
1+
import unittest2
22
from datetime import datetime, timedelta, date as dt_date
33
import zfslib as zfs
44
from zfslib_test_tools import *
@@ -52,7 +52,7 @@ def _checkPath(path):
5252
if b_cr: _checkPath(diff.snap_path_right)
5353

5454

55-
class Diff_Tests(unittest.TestCase):
55+
class Diff_Tests(unittest2.TestCase):
5656
def setUp(self):
5757
if len(snaps_varlog) < 2:
5858
raise Exception("Testing cannot be done. Please ensure that Dataset rpool/ROOT/<computer>/var/log has more than one snapshot")
@@ -159,7 +159,7 @@ def _verify_diffs(self, step, diffs):
159159

160160

161161

162-
class Poolset_Tests(unittest.TestCase):
162+
class Poolset_Tests(unittest2.TestCase):
163163
def test_find_dataset_for_path(self):
164164
path = '/var/log/apt/history.log'
165165
tup = poolset.find_dataset_for_path(path)
@@ -200,7 +200,7 @@ def test_find_dataset_for_path(self):
200200

201201

202202

203-
class Dataset_Tests(unittest.TestCase):
203+
class Dataset_Tests(unittest2.TestCase):
204204

205205
def test_get_rel_path(self):
206206
self.assertEqual(ds_varlog.get_rel_path('/var/log/apt/history.log'), '/apt/history.log')
@@ -212,7 +212,7 @@ def test_get_rel_path(self):
212212

213213

214214

215-
class Snapshot_Tests(unittest.TestCase):
215+
class Snapshot_Tests(unittest2.TestCase):
216216

217217
def test_resolve_snap_path(self):
218218
snap = snaps_varlog[1]
@@ -240,4 +240,5 @@ def test_resolve_snap_path(self):
240240

241241

242242
if __name__ == "__main__":
243-
unittest.main()
243+
unittest2.main()
244+
sys.exit(0)

tests/zfslib_test_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import datetime
55
import zfslib as zfs
66

7-
87
def dt_from_creation(creation):
98
return datetime.fromtimestamp(int(creation))
109

0 commit comments

Comments
 (0)