def test_generateTemplates(capsys): sourceFolder = common.createTestPath('source') templateFolder = os.path.join(sourceFolder, 'templates') destFolder = common.createTestPath('dest') common.setupPath(sourceFolder) common.setupPath(templateFolder) common.setupPath(destFolder) for file in templates.__templateFileList__: common.touchFile(os.path.join(templateFolder, file)) templates.generateTemplates(sourceFolder, destFolder) captured = capsys.readouterr() output = '' for file in templates.__templateFileList__: output += 'Copying template file {} to {}\n'.format( os.path.join(templateFolder, file), os.path.join(destFolder, file)) assert os.path.exists(os.path.join(destFolder, file)) assert captured.out == output templates.generateTemplates(sourceFolder, destFolder) captured = capsys.readouterr() output = '' for file in templates.__templateFileList__: output += 'Template file {} already exists\n'.format( os.path.join(destFolder, file)) assert os.path.exists(os.path.join(destFolder, file)) assert captured.out == output
def test_findFilesInvalidPath( ): common.touchFile( common.createTestPath( 'testFile1.x' ) ) common.touchFile( common.createTestPath( 'testFile2.x' ) ) common.touchFile( common.createTestPath( 'testFile3.y' ) ) fileList = misc.findFiles( '/a/test/path', '.x' ) assert not 'testFile1.x' in fileList assert not 'testFile2.x' in fileList assert not 'testFile3.y' in fileList
def test_findFilesSinglePath( ): common.touchFile( common.createTestPath( 'testFile1.x' ) ) common.touchFile( common.createTestPath( 'testFile2.x' ) ) common.touchFile( common.createTestPath( 'testFile3.y' ) ) fileList = misc.findFiles( common.rootPath, '.x' ) assert 'testFile1.x' in fileList assert 'testFile2.x' in fileList assert not 'testFile3.y' in fileList
def test_checkFileContentsSame( ): testString1 = 'This string is for testing!' testString2 = 'This string is also for testing!' with open( common.createTestPath( 'testFile1' ), 'w+' ) as writeFile: writeFile.write( testString1 ) with open( common.createTestPath( 'testFile2' ), 'w+' ) as writeFile: writeFile.write( testString2 ) assert misc.checkFileContentsSame( common.createTestPath( 'testFile1' ), testString1 ) assert not misc.checkFileContentsSame( common.createTestPath( 'testFile2' ), testString1 ) assert not misc.checkFileContentsSame( common.createTestPath( 'testFile3' ), testString1 )
def test_findFilesMultiplePaths( ): common.setupPath( common.createTestPath( 'folder1' ) ) common.setupPath( common.createTestPath( 'folder2' ) ) common.touchFile( common.createTestPath( 'testFile1.x' ) ) common.touchFile( common.createTestPath( 'folder1/testFile2.x' ) ) common.touchFile( common.createTestPath( 'folder2/testFile3.y' ) ) fileList = misc.findFiles( common.rootPath, '.x' ) assert 'testFile1.x' in fileList assert 'folder1/testFile2.x' in fileList assert not 'folder1/testFile3.y' in fileList assert not 'testFile3.y' in fileList
def test_createDir(): testPath = common.createTestPath('testDir') common.cleanupPath(testPath) misc.createDir(testPath) assert os.path.exists(testPath) misc.createDir(testPath) assert os.path.exists(testPath)
def test_createTestStubs( ): testRootPath = common.createTestPath( 'testRoot' ) [ testModules, includeFiles ] = __setupTestFiles__( ) mgr = filemgr.filemgr( [ __sourcePath1__, __sourcePath2__ ], [ __includePath1__, __includePath2__ ] ) mgr.createTestStubs( testRootPath ) for mod in testModules: assert os.path.exists( mod.testStubPath( testRootPath ) )
def test_setupDirectories(): testPath = common.createTestPath('testDir') common.cleanupPath(testPath) misc.setupDirectories( argparse.Namespace(workPath=testPath, outputDir='output', watchDir='watch')) assert os.path.exists(testPath) assert os.path.exists(os.path.join(testPath, 'output')) assert os.path.exists(os.path.join(testPath, 'watch'))
def test_createTestCMakeList( ): testRootPath = common.createTestPath( 'testRoot' ) common.setupPath( testRootPath ) [ testModules, includeFiles ] = __setupTestFiles__( ) mgr = filemgr.filemgr( [ __sourcePath1__, __sourcePath2__ ], [ __includePath1__, __includePath2__ ] ) mgr.createTestCMakeList( testRootPath ) assert os.path.exists( os.path.join( testRootPath, 'CMakeLists.txt' ) ) mgr.createTestCMakeList( testRootPath ) assert os.path.exists( os.path.join( testRootPath, 'CMakeLists.txt' ) )
def test_createTestStubsFileExists( ): testRootPath = common.createTestPath( 'testRoot' ) common.setupPath( testRootPath ) [ testModules, includeFiles ] = __setupTestFiles__( ) for mod in testModules: os.makedirs( os.path.dirname( mod.testStubPath( testRootPath ) ) ) common.touchFile( mod.testStubPath( testRootPath ) ) mgr = filemgr.filemgr( [ __sourcePath1__, __sourcePath2__ ], [ __includePath1__, __includePath2__ ] ) mgr.createTestStubs( testRootPath ) for mod in testModules: assert os.path.exists( mod.testStubPath( testRootPath ) )
def test_readWriteFile( testDataNotEmpty ): filePath = common.createTestPath( status.convmgrstatus.fileName ) if os.path.exists( filePath ): os.remove( filePath ) testDataNotEmpty.saveFile( ) assert os.path.exists( filePath ) newData = status.convmgrstatus( common.rootPath ) newData.loadFile( ) for key in testDataNotEmpty.data: assert key in newData.data for file in testDataNotEmpty.data[ key ]: assert file in newData.data[ key ]
def test_readFile(testData, fileName): with open(common.createTestPath(fileName), 'w+') as json_file: json.dump({'testKey1': 'testValue1', 'testKey2': 4}, json_file) testData.readFile() if config.convmgrconfig.fileName == fileName: assert 'testKey1' in testData.data assert testData.getValue('testKey1') == 'testValue1' assert 'testKey2' in testData.data assert testData.getValue('testKey2') == 4 assert not 'testKey3' in testData.data assert testData.getValue('testKey3') == '' else: assert not 'testKey1' in testData.data assert not 'testKey2' in testData.data assert not 'testKey3' in testData.data
def test_constructor(testData): assert testData.filePath == common.createTestPath( config.convmgrconfig.fileName) assert not testData.data
#!/usr/bin/python3 import os import json import pytest try: from unittest import mock # python 3.3+ except ImportError: import mock # python 2.6-3.2 from unitygen import config from tests import common __testFilePath__ = common.createTestPath('testFile.json') __testData__ = { 'paths': { 'root': 'rootPath', 'sources': ['sourcePath1', 'sourcePath2'], 'includes': ['includePath1', 'includePath2'], 'test': 'testPath' } } def setup_function(): common.setupRoot() def teardown_function(): common.cleanupRoot()
def test_constructor( testData ): assert testData.fileName == common.createTestPath( status.convmgrstatus.fileName )
#!/usr/bin/python3 import os import pytest try: from unittest import mock # python 3.3+ except ImportError: import mock # python 2.6-3.2 from unitygen import filemgr from tests import common __sourcePath1__ = common.createTestPath( 'src1' ) __sourcePath2__ = common.createTestPath( 'src2' ) __includePath1__ = common.createTestPath( 'include1' ) __includePath2__ = common.createTestPath( 'include2' ) def setup_function( ): common.setupRoot( ) def teardown_function( ): common.cleanupRoot( ) def __setupTestFiles__( ): common.setupPath( __sourcePath1__ ) common.setupPath( __sourcePath2__ ) common.setupPath( os.path.join( __sourcePath1__, 'folder1' ) ) common.setupPath( __includePath1__ ) common.setupPath( __includePath2__ ) common.setupPath( os.path.join( __includePath1__, 'folder2' ) )