def test_ncnp(self): if p == "darwin" or p == "linux": self.assertTrue(n(paw1), "/pth1/pth2") self.assertTrue(n(paw2), "/pth2") elif p == "cygwin" or p == "win32": self.assertTrue(n(paw1), "\\pth1\\pth2") self.assertTrue(n(paw2), "\\pth2")
def test_get_ap_1(self): self.assertEqual(gp1(pa), n("/pth1/pth2/pth3/pth4")) self.assertEqual(gp1(pa1), n("/pth1/pth2")) self.assertEqual(gp1(pa2), n("/pth4")) self.assertEqual(gp1(paw1), n("/pth1")) self.assertEqual(gp1(paw1), n("/pth1/.")) self.assertEqual(gp1(paw2), n("/pth1/..")) self.assertNotEqual(gp1(pa), n("/pth1/pth2/pth3")) self.assertNotEqual(gp1(pa1), n("/pth1")) self.assertNotEqual(gp1(pa2), n("/")) self.assertNotEqual(gp1(paw2), n("/pth1")) with self.assertRaises(EX_NAP): gp1(prd)
def test_chk_md_b(self): f = j(dm, "f.md") cr(f, False) ls = ["1", "2", "3"] am(f, ls) self.assertFalse(cmb(f)) de(f) f = j(dm, "f.md") cr(f, False) self.assertTrue(cmb(f)) de(f) f = n("./f.f") with self.assertRaises(EX_NAP): cmb(f) f = j(dm, "f.md") with self.assertRaises(EX_NEF): cmb(f) f = j(dm, "f.f") cr(f, False) with self.assertRaises(EX_NEMD): cmb(f) de(f)
def test_apnd_md(self): f = j(dm, "f.md") cr(f, False) ls = ["1", "2", "3"] self.assertTrue(am(f, ls)) de(f) f = j(dm, "f.md") cr(f, False) lns = [1, "2", "3"] with self.assertRaises(EX_LNAS): am(f, lns) de(f) f = n("./f.f") ls = ["1", "2", "3"] with self.assertRaises(EX_NAP): am(f, ls) f = j(dm, "f.md") ls = ["1", "2", "3"] with self.assertRaises(EX_NEF): am(f, ls) f = j(dm, "f.f") ls = ["1", "2", "3"] cr(f, False) with self.assertRaises(EX_NEMD): am(f, ls) de(f)
def test_get_lst_n_md(self): f1 = j(dm, "f1.md") cr(f1, False) f2 = j(dm, "f2.f") cr(f2, False) f3 = j(dm, "f3.f") cr(f3, False) put("glnm(dm)", glnm(dm)) de(f1) de(f2) de(f3) d = j(dm, "d") cr(d, True) with self.assertRaises(EX_DND): glnm(dm) de(d) f1 = j(dm, "f1.md") cr(f1, False) f2 = j(dm, "f2.md") cr(f2, False) with self.assertRaises(EX_EMMD): glnm(dm) de(f1) de(f2) d = n("./") with self.assertRaises(EX_NAP): glnm(d) d = j(dm, "d") with self.assertRaises(EX_NED): glnm(d)
def test_get_md(self): f = j(dm, "f.md") cr(f, False) put("gm(dm)", gm(dm)) de(f) f1 = j(dm, "f1.md") f2 = j(dm, "f2.md") cr(f1, False) cr(f2, False) with self.assertRaises(EX_EMMD): gm(dm) de(f1) de(f2) d = n("./") with self.assertRaises(EX_NAP): gm(d) d = j(dm, "d") with self.assertRaises(EX_NED): gm(d) with self.assertRaises(EX_NEMD): gm(dm)
def test_get_img_dim_w(self): f = j(dm, "f.bmp") cid(f) put("gidw(f)", gidw(f)) de(f) f = j(dm, "f.jpeg") cid(f) put("gidw(f)", gidw(f)) de(f) f = j(dm, "f.jpg") cid(f) put("gidw(f)", gidw(f)) de(f) f = j(dm, "f.png") cid(f) put("gidw(f)", gidw(f)) de(f) f = n("./f.f") with self.assertRaises(EX_NAP): gidw(f) f = j(dm, "f.bmp") with self.assertRaises(EX_NEF): gidw(f) f = j(dm, "f.f") cr(f, False) with self.assertRaises(EX_NIMG): gidw(f) de(f)
def test_crt_md(self): f = j(dm, "f.md") self.assertTrue(crm(f)) de(f) f = n("./f.md") with self.assertRaises(EX_NAP): crm(f) f = j(dm, "f.f") cr(f, False) with self.assertRaises(EX_NEMD): crm(f) de(f)
def test_wrt_md_b(self): f = j(dm, "f.md") cr(f, False) self.assertTrue(wbm(f)) de(f) f = n("./f.f") with self.assertRaises(EX_NAP): wbm(f) f = j(dm, "f.md") with self.assertRaises(EX_NEF): wbm(f) f = j(dm, "f.f") cr(f, False) with self.assertRaises(EX_NEMD): wbm(f) de(f)
def test_crt_apnm_note(self): cn_ = cn(dm) put("cn(dm).ap_di", cn_.ap_di) put("cn(dm).ap_md", cn_.ap_md) put("cn(dm).nm_di", cn_.nm_di) put("cn(dm).nm_md", cn_.nm_md) d = j(dm, "d") cr(d, True) with self.assertRaises(EX_DND): cn(dm) de(d) d = j(dm, "d") with self.assertRaises(EX_NED): cn(d) d = n("./") with self.assertRaises(EX_NAP): cn(d)
def test_chk_exst_md(self): self.assertFalse(cm(dm)) f = j(dm, "f.f") cr(f, False) self.assertFalse(cm(dm)) de(f) f = j(dm, "j.md") cr(f, False) self.assertTrue(cm(dm)) de(f) d = n("./") with self.assertRaises(EX_NAP): cm(d) d = j(dm, "d") with self.assertRaises(EX_NED): cm(d)
def test_rd_md(self): f = j(dm, "f.md") cr(f, False) ls = ["1", "2", "3"] am(f, ls) put("rd(f)", rd(f)) de(f) f = n("./f.f") with self.assertRaises(EX_NAP): rd(f) f = j(dm, "f.f") with self.assertRaises(EX_NEF): rd(f) f = j(dm, "f.f") cr(f, False) with self.assertRaises(EX_NEMD): rd(f) de(f)
from pth import get_ap_1 as gp1 from pth import get_ap_innermst as gpi from pth import get_ap_x as gpx from pth import get_ext as ge from pth import get_no_ext as gne from pth import get_sp as gsp from pth import rm_ext as re from pth import rm_ext_bak as reb from pth import rm_ext_md as rem from pth import jo as j from pth import ncnp as n from pth import rm_sp_lst as rsl from exc import ExceptionNotAbsolutePath as EX_NAP from exc import ExceptionNotExistsFileExtension as EX_NFE pa = n("/pth1/pth2/pth3/pth4/pth5") # Absolute path. pa1 = n("/pth1/pth2/pth3" ) # Absolute path first part for unit testing join function. pa2 = n( "/pth4/pth5") # Absolute path second part for unit testing join function. pafl = n("/pth1/pth2/pth3/pth4/pth5/fi.fi") # Longer absolute path to file. pafs = n("fi.fi") # Shorter absolute path to file. pas = n("/pth1/pth2/pth3/pth4/pth5/" ) # Absolute path with system separator as a latest character. paw1 = n( "/pth1/./pth2" ) # Absolute path with single dot to shorten URL for unit testing URL normalizer function. paw2 = n( "/pth1/../pth2" ) # Absolute path with double dots to shorten URL for unit testing URL normalizer function. pi = n("/pth1/pth2/pth3/pth4/pth5\\") # Illegal path.
def test_repair(self): d = j(dm, "d") cr(d, True) fm = j(d, "fm.md") cr(fm, False) am(fm, var.smpl_md) f1 = j(d, "f1.bmp") cid(f1) f2 = j(d, "f2.jpeg") cid(f2) f3 = j(d, "f3.jpg") cid(f3) f4 = j(d, "f4.png") cid(f4) f5 = j(d, "f5.fi") cr(f5, False) f6 = j(d, "f6.fi") cr(f6, False) f7 = j(d, "8.fi") cr(f7, False) dn = r(d) self.assertNotEqual(d, dn) de(dn) d = j(dm, "20000101-0000-cet-d") cr(d, True) fm = j(d, "fm.md") cr(fm, False) am(fm, var.smpl_md_prefix) f1 = j(d, "20010101-0000-cet-f1.bmp") cid(f1) f2 = j(d, "f2.jpeg") cid(f2) f3 = j(d, "f3.jpg") cid(f3) f4 = j(d, "f4.png") cid(f4) f5 = j(d, "f5.fi") cr(f5, False) f6 = j(d, "f6.fi") cr(f6, False) f7 = j(d, "8.fi") cr(f7, False) dn = r(d) self.assertEqual(d, dn) de(dn) d = j(dm, "20010101-0000-cet-d") cr(d, True) fm = j(d, "20010101-0000-cet-d.md") cr(fm, False) am(fm, var.smpl_md_correct) f1 = j(d, "20010101-0000-cet-1.png") cid(f1) f2 = j(d, "20010101-0000-cet-2.png") cid(f2) f3 = j(d, "20010101-0000-cet-3.png") cid(f3) f4 = j(d, "20010101-0000-cet-4.png") cid(f4) f5 = j(d, "20010101-0000-cet-5-test.pdf") cr(f5, False) f6 = j(d, "20010101-0000-cet-6-test.pdf") cr(f6, False) dn = r(d) self.assertEqual(d, dn) de(dn) f1 = j(dm, "f1.md") cr(f1, False) f2 = j(dm, "f2.md") cr(f2, False) with self.assertRaises(EX_EMMD): r(dm) de(f1) de(f2) d = j(dm, "d") cr(d, True) f = j(d, "f.md") cr(f, False) with self.assertRaises(EX_MDNC): r(d) de(d) d = j(dm, "20000101-0000-cet-d") cr(d, True) f = j(d, "f.md") cr(f, False) with self.assertRaises(EX_MDNC): r(d) de(d) d = n("./") with self.assertRaises(EX_NAP): r(d) d = j(dm, "d") with self.assertRaises(EX_NED): r(d) d = j(dm, "d") cr(d, True) with self.assertRaises(EX_NEMD): r(d) de(d)
def test_init(self): d = j(dm, "d") cr(d, True) f1 = j(d, "f1.bmp") cid(f1) f2 = j(d, "f2.jpeg") cid(f2) f3 = j(d, "f3.jpg") cid(f3) f4 = j(d, "f4.png") cid(f4) f5 = j(d, "f5.fi") cr(f5, False) f6 = j(d, "f6.fi") cr(f6, False) f7 = j(d, "8.fi") cr(f7, False) dn = i(d) self.assertNotEqual(d, dn) de(dn) d = j(dm, "20000101-0000-cet-d") cr(d, True) f1 = j(d, "f1.bmp") cid(f1) f2 = j(d, "f2.jpeg") cid(f2) f3 = j(d, "f3.jpg") cid(f3) f4 = j(d, "f4.png") cid(f4) f5 = j(d, "f5.fi") cr(f5, False) f6 = j(d, "f6.fi") cr(f6, False) f7 = j(d, "8.fi") cr(f7, False) dn = i(d) self.assertEqual(d, dn) de(dn) d = j(dm, "20010101-0000-cet-d") cr(d, True) fm = j(d, "20010101-0000-cet-d.md") cr(fm, False) f1 = j(d, "20010101-0000-cet-1.png") cid(f1) f2 = j(d, "20010101-0000-cet-2.png") cid(f2) f3 = j(d, "20010101-0000-cet-3.png") cid(f3) f4 = j(d, "20010101-0000-cet-4.png") cid(f4) f5 = j(d, "20010101-0000-cet-5-test.pdf") cr(f5, False) f6 = j(d, "20010101-0000-cet-6-test.pdf") cr(f6, False) dn = i(d) self.assertEqual(d, dn) de(dn) f1 = j(dm, "f1.md") cr(f1, False) f2 = j(dm, "f2.md") cr(f2, False) with self.assertRaises(EX_EMMD): i(dm) de(f1) de(f2) d = j(dm, "d") cr(d, True) f = j(d, "f.md") cr(f, False) ls = ["1", "2", "3"] am(f, ls) with self.assertRaises(EX_MDC): i(d) de(d) d = j(dm, "20000101-0000-cet-d") cr(d, True) f = j(d, "f.md") cr(f, False) ls = ["1", "2", "3"] am(f, ls) with self.assertRaises(EX_MDC): i(d) de(d) d = n("./") with self.assertRaises(EX_NAP): i(d) d = j(dm, "d") with self.assertRaises(EX_NED): i(d)
def test_get_ap_x(self): """ Due to `ncnp()`. """ self.assertEqual(gpx(pa, 10), n("/")) self.assertEqual(gpx(pa, 10), n("/")) self.assertEqual(gpx(pa1, 10), n("/")) self.assertEqual(gpx(pa1, 10), n("/")) self.assertEqual(gpx(pa2, 10), n("/")) self.assertEqual(gpx(pa2, 10), n("/")) self.assertEqual(gpx(paw1, 10), n("/")) self.assertEqual(gpx(paw1, 10), n("/")) self.assertEqual(gpx(paw2, 10), n("/")) self.assertEqual(gpx(paw2, 10), n("/")) self.assertEqual(gpx(pa, 2), n("/pth1/pth2/pth3")) self.assertEqual(gpx(pa1, 2), n("/pth1")) self.assertEqual(gpx(pa2, 2), n("/")) self.assertNotEqual(gpx(pa, 2), n("/pth1/pth2/pth3/pth4")) self.assertNotEqual(gpx(pa1, 2), n("/pth1/pth2")) self.assertNotEqual(gpx(pa2, 2), n("/pth4")) self.assertNotEqual(gpx(paw1, 2), n("/pth1")) self.assertNotEqual(gpx(paw1, 2), n("/pth1/")) self.assertNotEqual(gpx(paw2, 2), n("/pth1")) self.assertNotEqual(gpx(paw2, 2), n("/pth1/")) with self.assertRaises(EX_NAP): gpx(prd, 2)
from exc import ExceptionExistsDirectoryInDirectory as EX_DND from exc import ExceptionListNotAllString as EX_LNAS from exc import ExceptionMDFileContent as EX_MDC from exc import ExceptionMDFileNoContent as EX_MDNC from exc import ExceptionNotAbsolutePath as EX_NAP from exc import ExceptionNotAbsolutePath as EX_NAP from exc import ExceptionNotExistsDirectory as EX_NED from exc import ExceptionNotExistsFile as EX_NEF from exc import ExceptionNotExistsFileExtension as EX_NFE from exc import ExceptionNotExistsMDFile as EX_NEMD from exc import ExceptionNotExistsOpenMode as EX_NEOM import var """ It is important to have separate folder for each unit test Python file. """ # This unit test home directory. du = n("/home/{}").format(getpass.getuser()) # Unix. dw = "C:\\Users\\{}".format(getpass.getuser()) # Windows. d = du # The used directory. if p == "cygwin" or p == "win32": d = dw # Check if this program runs in Windows platform. dm = j(d, "dm_test_note") # Main directory for this unit test. """ The ideal case scenario is to only have one upper classification. This note is not relevant anymore since I put everything locally into the test function itself. But I can use this practice for future project. Wrong and current example: file_img_jpg = ["jpg1", "jpg2"] file_img_png = ["png1", "png2"] file_md = ["file1", "file2", "file3"] file_img = file_img_jpg + file_img_png
from difi import frmt_mkdocs as fm from difi import get_lst as gl from difi import mov as m from difi import ren as r from difi import ren_recr as rr from difi import wlk_get_note as wgn from pth import get_ap_innermst as gpi from pth import jo as j from pth import ncnp as n from exc import ExceptionExistsDirectoryOrFile as EX_DF from exc import ExceptionNotAbsolutePath as EX_NAP from exc import ExceptionNotExistsDirectory as EX_ND from exc import ExceptionNotExistsDirectoryOrFile as EX_NDF from exc import ExceptionSamePath as EX_SP du = n("/home/{}".format(getpass.getuser())) dw = n("C:\\{}\\Documents and Settings\\My Documents".format( getpass.getuser())) d = du # Unix platform. if p == "cygwin" or p == "win32": d = dw # Windows platform. dm = j(d, "dm_test_difi") # Main directory for this unit test. dc = j(dm, "dc") # Copied test directory that is exists. dd = j(dm, "dd") # Deleted test directory that is exists. dex = j(dm, "dex") # Test directory that is exists. dmv1 = j(dm, "dmv1") # Moved test directory 1 that is exists. dmv2 = j(dm, "dmv2") # Moved test directory 2 that is exists. fc = j(dm, "fc.f") # Copied test file that is exists. fd = j(dm, "fd.f") # Deleted test file that is exists. fe = j(dm, "fe.f") # Test file that is exists.
def test_crt_apnm_img_cnvrt(self): f = j(dm, "f.bmp") cid(f) cni_ = cc(f) put("cc(f).ap_bak", cni_.ap_bak) put("cc(f).ap_cn", cni_.ap_cn) put("cc(f).nm_bak", cni_.nm_bak) put("cc(f).nm_cn", cni_.nm_cn) de(f) f = j(dm, "f.jpeg") cid(f) cni_ = cc(f) put("cc(f).ap_bak", cni_.ap_bak) put("cc(f).ap_cn", cni_.ap_cn) put("cc(f).nm_bak", cni_.nm_bak) put("cc(f).nm_cn", cni_.nm_cn) de(f) f = j(dm, "f.jpg") cid(f) cni_ = cc(f) put("cc(f).ap_bak", cni_.ap_bak) put("cc(f).ap_cn", cni_.ap_cn) put("cc(f).nm_bak", cni_.nm_bak) put("cc(f).nm_cn", cni_.nm_cn) de(f) f = j(dm, "f.png") cid(f) cni_ = cc(f) put("cc(f).ap_bak", cni_.ap_bak) put("cc(f).ap_cn", cni_.ap_cn) put("cc(f).nm_bak", cni_.nm_bak) put("cc(f).nm_cn", cni_.nm_cn) de(f) f = n("./f.f") with self.assertRaises(EX_NAP): cc(f) f = j(dm, "f.bmp") with self.assertRaises(EX_NEF): cc(f) f = j(dm, "f.jpeg") with self.assertRaises(EX_NEF): cc(f) f = j(dm, "f.jpg") with self.assertRaises(EX_NEF): cc(f) f = j(dm, "f.png") with self.assertRaises(EX_NEF): cc(f) f = j(dm, "f.f") cr(f, False) with self.assertRaises(EX_NIMG): cc(f) de(f)
def test_get_no_ext(self): self.assertEqual(gne(pafl), n("/pth1/pth2/pth3/pth4/pth5/fi")) self.assertEqual(gne(pafs), "fi")