def test_testName(self): color.blue("test here baby") fileContent = """commentCollection = require '../commentCollection.iced' th = require 'throw' module.exports = (db, text, orgId, cb)-> collection = commentCollection db await collection.ensureIndex {Info: text}, defer() await collection.find({Info: text, OrgId: orgId}).sort({DateCreate: -1}).toArray defer err, comments cb null, comments""" result = callForSyncFunc.isItCb(fileContent) expected = True assertMy.equals(result, expected)
def do(targeFilename, sourceFilename): target = targeFilename source = sourceFilename print("target:", target, "-----------------------------------------------------") print("source:", source, "-----------------------------------------------------") rel = absRel.RelAndCutIfNodeModules(source, target) # 1) get fileName by filePath filename = absRel.filename(target) # 2) create string: #{fileName} = require '#{relativePath}' require = "{0} = require '{1}'".format(filename, rel) # 3) set to cliboard objectName - filename # 3.1) get param names: # get fileContent_target to load it once: fileContent_target = filer2.read(target) # check if function sync: sync = callForSyncFunc.isItSync(fileContent_target) color.red("sync in relativeRequireIced_model.py") print(sync) isCbWithouAutocb = callForSyncFunc.isItCb(fileContent_target) color.red("isCbWithouAutocb in relativeRequireIced_model.py") print(isCbWithouAutocb) if isCbWithouAutocb: # (...,cb)-> params = getParams.getParamsCb(fileContent_target) ending = returnLast.getReturnParamsForAutocbCommaSeparated(fileContent_target) toClip = "await {0}{1} defer {2}".format(filename, params, ending) else: if sync: # load params sync params = callForSyncFunc.byFileContent(fileContent_target) returnParams = returnLast.returnParamsForSyncExpressionOrReturn(fileContent_target) toClip = "{2} = {0}{1}".format(filename, params, returnParams) else: # async: (..., autocb)-> params = getParams.getParamsAutocb(fileContent_target) autocbOneEnding = returnLast.autocbOneEnding(fileContent_target) if autocbOneEnding: toClip = "await {0}{1} defer {2}".format(filename, params, autocbOneEnding) else: ending = returnLast.doAllByFileName(target) toClip = "await {0}{1} defer result{2}".format(filename, params, ending) result = (require, toClip) return result