def setUp(self): self.tmp_dir = os.path.join(tempfile.gettempdir(), 'r_test') self.src_iso = os.path.join(os.path.join(os.getcwd(), 'test'), 'test.iso') self.squash_fs = os.path.join(os.path.join(os.getcwd(), 'test'), 'squash_test.squashfs') self.test_file = os.path.join(os.path.join(os.getcwd(), 'test'), 'test.txt') self.test_dir = os.path.join(os.path.join(os.getcwd(), 'test'), 'test_dir/') self.output_file = os.path.join(self.tmp_dir, 'custom.iso') self.engine = BuildEngine(distro='ubuntu', arch='x86', working_dir=self.tmp_dir, src_iso_filename=self.src_iso, output_file=self.output_file) self.engine.extract_iso()
class TestBuildEngine(unittest.TestCase): def setUp(self): self.tmp_dir = os.path.join(tempfile.gettempdir(), 'r_test') self.src_iso = os.path.join(os.path.join(os.getcwd(), 'test'), 'test.iso') self.squash_fs = os.path.join(os.path.join(os.getcwd(), 'test'), 'squash_test.squashfs') self.test_file = os.path.join(os.path.join(os.getcwd(), 'test'), 'test.txt') self.test_dir = os.path.join(os.path.join(os.getcwd(), 'test'), 'test_dir/') self.output_file = os.path.join(self.tmp_dir, 'custom.iso') self.engine = BuildEngine(distro='ubuntu', arch='x86', working_dir=self.tmp_dir, src_iso_filename=self.src_iso, output_file=self.output_file) self.engine.extract_iso() def testExtractIso(self): # assert iso extracts self.assertTrue(self.engine.extract_iso(), 'Error extracting iso...') self.assert_(os.listdir(self.engine.get_work_dir()) != 0, 'Error extracting ISO...') def testCreateIso(self): self.assertTrue(self.engine.extract_iso()) self.assert_(self.engine.create_iso()) self.assert_(os.path.exists(self.engine.get_output_filename())) os.system('cp %s /home/ehazlett/sort/' % (self.output_file)) def testExtractLiveSquashFs(self): # assert squash extracts self.assertTrue(self.engine.extract_live_fs(), 'Error extracting squash filesystem...') self.assert_(os.listdir(self.engine.get_live_fs_dir()) != 0, 'Error extracting squash filesystem...') def testBuildLiveSquashFs(self): # assert squash fs is built self.assertTrue(self.engine.extract_live_fs(), 'Error extracting live filesystem...') self.assertTrue(self.engine.build_live_fs()) self.assertTrue(os.path.exists(self.engine.get_live_fs_filename()), 'Live Filesystem does not exist...') def _testAddToFs(self): self.assertTrue(self.engine.add_to_target(self.test_file, '/opt', True), 'Error copying file...') self.assertTrue(os.path.exists(self.engine.get_live_fs_dir() + '/opt/' + os.path.basename(self.test_file)), 'File not copied...') self.assertTrue(self.engine.add_to_target(self.test_dir, '/opt', True), 'Error copying directory...') self.assertTrue(os.path.exists(self.engine.get_live_fs_dir() + '/opt/' + self.test_dir.split('/')[-2]), 'Directory not copied...') def testAddProjectData(self): p = Project(os.path.join(os.path.join(os.getcwd(), 'test'), 'test_project.rpj')) self.engine.set_project(p) self.assertTrue(self.engine.add_project_data()) self.assertTrue(os.path.exists(os.path.join(os.path.join(self.engine.get_live_fs_dir(), 'opt'), 'testfile'))) def tearDown(self): try: if os.path.exists(self.tmp_dir): shutil.rmtree(self.tmp_dir) self.assertFalse(os.path.exists(self.tmp_dir), 'Temporary directory not removed: %s' % (self.tmp_dir)) except Exception, d: # ignore cleanup errors print('Unable to cleanup from TestBuilder.tearDown: %s' % (d))
class TestBuildEngine(unittest.TestCase): def setUp(self): self.tmp_dir = os.path.join(tempfile.gettempdir(), 'r_test') self.src_iso = os.path.join(os.path.join(os.getcwd(), 'test'), 'test.iso') self.squash_fs = os.path.join(os.path.join(os.getcwd(), 'test'), 'squash_test.squashfs') self.test_file = os.path.join(os.path.join(os.getcwd(), 'test'), 'test.txt') self.test_dir = os.path.join(os.path.join(os.getcwd(), 'test'), 'test_dir/') self.output_file = os.path.join(self.tmp_dir, 'custom.iso') self.engine = BuildEngine(distro='ubuntu', arch='x86', working_dir=self.tmp_dir, src_iso_filename=self.src_iso, output_file=self.output_file) self.engine.extract_iso() def testExtractIso(self): # assert iso extracts self.assertTrue(self.engine.extract_iso(), 'Error extracting iso...') self.assert_( os.listdir(self.engine.get_work_dir()) != 0, 'Error extracting ISO...') def testCreateIso(self): self.assertTrue(self.engine.extract_iso()) self.assert_(self.engine.create_iso()) self.assert_(os.path.exists(self.engine.get_output_filename())) os.system('cp %s /home/ehazlett/sort/' % (self.output_file)) def testExtractLiveSquashFs(self): # assert squash extracts self.assertTrue(self.engine.extract_live_fs(), 'Error extracting squash filesystem...') self.assert_( os.listdir(self.engine.get_live_fs_dir()) != 0, 'Error extracting squash filesystem...') def testBuildLiveSquashFs(self): # assert squash fs is built self.assertTrue(self.engine.extract_live_fs(), 'Error extracting live filesystem...') self.assertTrue(self.engine.build_live_fs()) self.assertTrue(os.path.exists(self.engine.get_live_fs_filename()), 'Live Filesystem does not exist...') def _testAddToFs(self): self.assertTrue( self.engine.add_to_target(self.test_file, '/opt', True), 'Error copying file...') self.assertTrue( os.path.exists(self.engine.get_live_fs_dir() + '/opt/' + os.path.basename(self.test_file)), 'File not copied...') self.assertTrue(self.engine.add_to_target(self.test_dir, '/opt', True), 'Error copying directory...') self.assertTrue( os.path.exists(self.engine.get_live_fs_dir() + '/opt/' + self.test_dir.split('/')[-2]), 'Directory not copied...') def testAddProjectData(self): p = Project( os.path.join(os.path.join(os.getcwd(), 'test'), 'test_project.rpj')) self.engine.set_project(p) self.assertTrue(self.engine.add_project_data()) self.assertTrue( os.path.exists( os.path.join( os.path.join(self.engine.get_live_fs_dir(), 'opt'), 'testfile'))) def tearDown(self): try: if os.path.exists(self.tmp_dir): shutil.rmtree(self.tmp_dir) self.assertFalse( os.path.exists(self.tmp_dir), 'Temporary directory not removed: %s' % (self.tmp_dir)) except Exception, d: # ignore cleanup errors print('Unable to cleanup from TestBuilder.tearDown: %s' % (d))