Example #1
0
	def test_jinja2(self):
		template='Hello {{a}}{{b}}!'
		expected='Hello PicoCM!'
		with TempFile() as templatefile:
			with TempFile() as dst:
				picocm.file_write(templatefile.name, template)
				self.assertTrue(picocm.jinja2(dst.name, templatefile.name, args={'a':'Pico', 'b':'CM'}))
				self.assertFalse(picocm.jinja2(dst.name, templatefile.name, args={'a':'Pico', 'b':'CM'}))
				self.assertEqual(expected, picocm.file_read(dst.name))
Example #2
0
	def test_file_copy(self):
		with TempFile() as src:
			with TempFile() as dst:
				self.assertTrue(picocm.file_write(src.name, 'test_file_copy'))
				self.assertTrue(picocm.file_copy(dst.name, src.name))
				self.assertEqual('test_file_copy', picocm.file_read(dst.name))
				self.assertFalse(picocm.file_copy(dst.name, src.name))
Example #3
0
	def test_file_unzip(self):
		with TempFile() as f:
			with TempDir() as d:
				picocm.file_write(os.path.join(d.name, 'abc.txt'), 'x')
				picocm.file_write(os.path.join(d.name, 'ijk.txt'), 'y')
				picocm.file_write(os.path.join(d.name, 'lmn/pqr.txt'), 'z')
				subprocess.check_call(['zip', '-r', '-q', f.name, '.'], cwd=d.name)
			with TempDir() as d:
				self.assertTrue(picocm.file_unzip(f.name, dir=d.name))
				self.assertTrue(picocm.file_unzip(f.name, dir=d.name))
				self.assertEqual('x', picocm.file_read(os.path.join(d.name, 'abc.txt')))
				self.assertEqual('y', picocm.file_read(os.path.join(d.name, 'ijk.txt')))
				self.assertEqual('z', picocm.file_read(os.path.join(d.name, 'lmn/pqr.txt')))
Example #4
0
	def test_file_write_then_read(self):
		with TempFile() as dst:
			self.assertTrue(picocm.file_write(dst.name, 'hello'))
			self.assertEqual('hello', picocm.file_read(dst.name))