if SYS.version_info >= (3,):
def _bin(text): return text.encode()
def _text(bin): return bin.decode()
+ xrange = range
else:
def _bin(text): return text
def _text(bin): return bin
must_equal(data, _bin("Hello, world!"))
## mdup
-## print(";; test mdup...")
+print(";; test mdup...")
+def mkfd():
+ fd = OS.open(",delete-me", OS.O_WRONLY | OS.O_CREAT, 0o666)
+ OS.unlink(",delete-me")
+ return fd
+def fid(fd):
+ st = OS.fstat(fd)
+ return st.st_dev, st.st_ino
+initial = [mkfd() for i in xrange(5)]
+ref = [fid(fd) for fd in initial]
+op = [(initial[0], initial[1]),
+ (initial[1], initial[2]),
+ (initial[2], initial[0]),
+ (initial[0], initial[3]),
+ (initial[3], -1),
+ (initial[0], initial[4])]
+M.mdup(op)
+for have, want in op:
+ if want != -1: must_equal(have, want)
+must_equal(op[0][0], initial[1]); must_equal(fid(op[0][0]), ref[0])
+must_equal(op[1][0], initial[2]); must_equal(fid(op[1][0]), ref[1])
+must_equal(op[2][0], initial[0]); must_equal(fid(op[2][0]), ref[2])
+must_equal(op[3][0], initial[3]); must_equal(fid(op[3][0]), ref[0])
+pass; must_equal(fid(op[4][0]), ref[3])
+must_equal(op[5][0], initial[4]); must_equal(fid(op[5][0]), ref[0])
+for fd, _ in op: OS.close(fd)
+
+## (not testing detachtty and daemonize)
+
## Done!