def test0(self): def fileCheck(*fpaths): for fpath in fpaths: self.assertTrue(fs.exists(fpath)) self.assertTrue(fs.isfile(fpath)) self.assertFalse(fs.isdir(fpath)) def dirCheck(*fpaths): for fpath in fpaths: self.assertTrue(fs.exists(fpath)) self.assertFalse(fs.isfile(fpath)) self.assertTrue(fs.isdir(fpath)) fs = MockFS() self.assertFalse(fs.exists('src/math/vector.c')) self.assertFalse(fs.isfile('src/math/vector.c')) self.assertFalse(fs.isdir('src/math/vector.c')) fs.mkdirs('src/math/utils') fs.write('README.txt', 'hello') self.assertEquals('hello', fs.read('README.txt')) fs.write('README.txt', 'Hello!') self.assertEquals('Hello!', fs.read('README.txt')) fs.write('src/main.c', '// main') self.assertEquals('// main', fs.read('src/main.c')) try: fs.mkdirs('src/main.c/utils') self.fail() except: pass print fs.show() fileCheck('README.txt', 'src/main.c') dirCheck('', 'src', 'src/math', 'src/math/', 'src/math/utils')
def testRmDir(self): fs = MockFS() fs.mkdirs('src/petymeg/pupak') fs.mkdirs('src/hallo/csocsi') self.assertTrue(fs.isdir('src/petymeg/pupak')) fs.rmdir('src/petymeg/pupak') fs.rmdir('src/hallo/csocsi') print fs.show()
def test0(self): def createTasks(bldr, cont): return self.createTasks(bldr, cont) cont = ContentHelper( cEnts=['main', 'helper', 'mgr'], vEnts=['core', 'CzokCodec', 'SPI'], libPath='out/sw/liba.so', binPath='out/hw/a.bin', cfgPath='cfg/pupak.desc', cfg=('c: mp3\nc: ogg\nc: avi\nc:mp4\n' 'v:add8_8_C\nv:mul16_16\nv: CzokEngiene: 10')) print '--- clean all ---' fs = MockFS() cont.create(fs) # print 'FS content before build:\n' + fs.show() with Builder(fs=fs) as bldr: createTasks(bldr, cont) self.assertEquals(0, bldr.buildOne('all')) allTasks = bldr.db.taskIdSavedTaskDict.keys() self.assertEquals(A_BIN_REF, fs.read('out/hw/a.bin')) self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so')) # print 'FS content after build:\n' + fs.show() with Builder(fs=fs) as bldr: createTasks(bldr, cont) # logger.setLevel(logging.DEBUG) self.cleanAndMatchOutput( bldr, 'all', ['INFO: Removed folder: gen', 'INFO: Removed folder: out']) print 'FS content after clean All:\n' + fs.show() # print str(fs.getFileList()) for d in ('gen', 'out'): self.assertFalse(fs.isdir(d)) files = [ 'cfg/pupak.desc', 'src/helper.c', 'src/main.c', 'src/mgr.c', 'vhdl/CzokCodec.vhdl', 'vhdl/SPI.vhdl', 'vhdl/core.vhdl', 'default.xbuild' ] for f in files: self.assertTrue(fs.isfile(f), '{} does not exist'.format(f)) # check DB # print fs.read('default.xbuild') self.checkDB(fs, allTasks, allTasks) print '--- clean hwTask ---' fs = MockFS() cont.create(fs) # print 'FS content before build:\n' + fs.show() with Builder(fs=fs) as bldr: createTasks(bldr, cont) bldr.buildOne('all') allTasks = bldr.db.taskIdSavedTaskDict.keys() # print 'FS content after build:\n' + fs.show() with Builder(fs=fs) as bldr: createTasks(bldr, cont) # logger.setLevel(logging.DEBUG) self.cleanAndMatchOutput(bldr, 'hwTask', ['INFO: Removed folder: out/hw']) print 'FS content after clean All:\n' + fs.show() # print str(fs.getFileList()) for d in ['out/hw']: self.assertFalse(fs.isdir(d)) files = [ 'cfg/pupak.desc', 'gen/pupak/src/avi.c', 'gen/pupak/src/mp3.c', 'gen/pupak/src/mp4.c', 'gen/pupak/src/ogg.c', 'out/sw/avi.o', 'out/sw/helper.o', 'out/sw/liba.so', 'out/sw/main.o', 'out/sw/mgr.o', 'out/sw/mp3.o', 'out/sw/mp4.o', 'out/sw/ogg.o', 'src/helper.c', 'src/main.c', 'src/mgr.c', 'vhdl/CzokCodec.vhdl', 'vhdl/SPI.vhdl', 'vhdl/core.vhdl', 'default.xbuild' ] for f in files: self.assertTrue(fs.isfile(f), '{} does not exist'.format(f)) # print str(sorted(allTasks)) removedTasks = [ 'hwTask', 'out/hw/CzokCodec.o', 'out/hw/CzokEngiene.o', 'out/hw/SPI.o', 'out/hw/add8_8_C.o', 'out/hw/core.o', 'out/hw/mul16_16.o' ] # check DB # print fs.read('default.xbuild') self.checkDB(fs, removedTasks, allTasks) print '--- clean out/hw/CzokEngiene.o ---' fs = MockFS() cont.create(fs) # print 'FS content before build:\n' + fs.show() with Builder(fs=fs) as bldr: createTasks(bldr, cont) bldr.buildOne('all') allTasks = bldr.db.taskIdSavedTaskDict.keys() # print 'FS content after build:\n' + fs.show() with Builder(fs=fs) as bldr: createTasks(bldr, cont) # logger.setLevel(logging.DEBUG) self.cleanAndMatchOutput( bldr, 'out/hw/CzokEngiene.o', ['INFO: Removed file: out/hw/CzokEngiene.o']) print 'FS content after clean out/hw/CzokEngiene.o:\n' + fs.show() # print str(fs.getFileList()) # for d in ['out/hw']: self.assertFalse(fs.isdir(d)) files = [ 'cfg/pupak.desc', 'gen/pupak/src/avi.c', 'gen/pupak/src/mp3.c', 'gen/pupak/src/mp4.c', 'gen/pupak/src/ogg.c', 'gen/pupak/vhdl/CzokEngiene.vhdl', 'gen/pupak/vhdl/add8_8_C.vhdl', 'gen/pupak/vhdl/mul16_16.vhdl', 'out/hw/CzokCodec.o', 'out/hw/SPI.o', 'out/hw/a.bin', 'out/hw/add8_8_C.o', 'out/hw/core.o', 'out/hw/mul16_16.o', 'out/sw/avi.o', 'out/sw/helper.o', 'out/sw/liba.so', 'out/sw/main.o', 'out/sw/mgr.o', 'out/sw/mp3.o', 'out/sw/mp4.o', 'out/sw/ogg.o', 'src/helper.c', 'src/main.c', 'src/mgr.c', 'vhdl/CzokCodec.vhdl', 'vhdl/SPI.vhdl', 'vhdl/core.vhdl', 'default.xbuild' ] for f in files: self.assertTrue(fs.isfile(f), '{} does not exist'.format(f)) # print str(sorted(allTasks)) removedTasks = ['out/hw/CzokEngiene.o'] # check DB # print fs.read('default.xbuild') self.checkDB(fs, removedTasks, allTasks) print '--- cleanAll() ---' fs = MockFS() cont.create(fs) # print 'FS content before build:\n' + fs.show() with Builder(fs=fs) as bldr: createTasks(bldr, cont) bldr.buildOne('all') allTasks = bldr.db.taskIdSavedTaskDict.keys() with Builder(fs=fs) as bldr: createTasks(bldr, cont) # logger.setLevel(logging.DEBUG) bldr.db.cleanAll() # TODO: asserts print 'FS content after cleanAll():\n' + fs.show() # print str(fs.getFileList()) for d in ('gen', 'out'): self.assertFalse(fs.isdir(d)) files = [ 'cfg/pupak.desc', 'src/helper.c', 'src/main.c', 'src/mgr.c', 'vhdl/CzokCodec.vhdl', 'vhdl/SPI.vhdl', 'vhdl/core.vhdl', 'default.xbuild' ] for f in files: self.assertTrue(fs.isfile(f), '{} does not exist'.format(f)) # check DB # print fs.read('default.xbuild') self.checkDB(fs, allTasks, allTasks)