def test_backup05(self): """Pass if file outside the host root.""" book = Book(Host(self.test_root)) book.init_backup() book.backup(__file__) self.assertListEqual(os.listdir(self.test_wsbdir), [])
def test_backup04(self): """Pass if file not exist.""" test_file = os.path.join(self.test_wsbdir, 'icon', 'test.txt') book = Book(Host(self.test_root)) book.init_backup() book.backup(test_file) self.assertFalse(os.path.lexists(os.path.join(book.backup_dir, WSB_DIR, 'icon', 'test.txt')))
def test_backup03(self): """Pass if backup_dir not set.""" test_file = os.path.join(self.test_wsbdir, 'icon', 'test.txt') os.makedirs(os.path.dirname(test_file)) with open(test_file, 'w', encoding='UTF-8') as fh: fh.write('abc') test_stat = os.stat(test_file) book = Book(Host(self.test_root)) book.backup(test_file) self.assertListEqual(os.listdir(self.test_wsbdir), ['icon'])
def test_backup01(self): """A common case.""" test_file = os.path.join(self.test_root, 'tree', 'meta.js') os.makedirs(os.path.dirname(test_file)) with open(test_file, 'w', encoding='UTF-8') as fh: fh.write('abc') book = Book(Host(self.test_root)) book.init_backup() book.backup(test_file) with open(os.path.join(book.backup_dir, 'tree', 'meta.js'), encoding='UTF-8') as fh: self.assertEqual(fh.read(), 'abc')
def test_backup02(self): """A common directory case.""" test_dir = os.path.join(self.test_root, 'tree') os.makedirs(test_dir) with open(os.path.join(test_dir, 'meta.js'), 'w', encoding='UTF-8') as fh: fh.write('abc') with open(os.path.join(test_dir, 'toc.js'), 'w', encoding='UTF-8') as fh: fh.write('def') book = Book(Host(self.test_root)) book.init_backup() book.backup(test_dir) with open(os.path.join(book.backup_dir, 'tree', 'meta.js'), encoding='UTF-8') as fh: self.assertEqual(fh.read(), 'abc') with open(os.path.join(book.backup_dir, 'tree', 'toc.js'), encoding='UTF-8') as fh: self.assertEqual(fh.read(), 'def')