Пример #1
0
    def test_writeFile(self):
        path = os.path.join(currentFolder, '../writeThisFile.iced')
        filer.write(path, "")
        empty_expected = filer.read(path)
        self.assertEqual (empty_expected, "")

        actualValue = """ 3
        4
         5"""

        filer.write(path, actualValue) 
        mustEqualToActual = filer.read(path)
        self.assertEqual(mustEqualToActual, actualValue)
Пример #2
0
	def test_recursiveWrite(self):
		color.blue("test here baby")
		inputFileContent = """routes = require '../../routes/e'
rrnt = require '../f.iced'
db = require 'db'
module.exports = (url, param, test)->
	rrnt routes, url, param, test
	"""	
	# 	expected = """routes = require '../e.iced'
	# rrnt = require './k/f.iced'
	# db = require 'db'
	# module.exports = (url, param, test)->
	# 	rrnt routes, url, param, test
	# 	"""		
		path = "/Users/maks/Library/Application Support/Sublime Text 3/Packages/goodPath/forRecursiveTest"

		files = recursiveSearch_model.getAllFiles(path)
		for fileName in files:
			filer.write(fileName, inputFileContent)

		findAllRelative_model.repaireRecursive(path)
		
		for fileName in files:
			result = filer.read(fileName)
			self.assertNotEqual (result, inputFileContent)	
	def test_testName(self):
		color.blue("test here baby")

		filename = os.path.dirname(os.path.realpath(__file__)) + "/poligion/poligon.go"
		position = 56

		expected = os.path.dirname(os.path.realpath(__file__)) +  "/poligion/Test_doAllForMiByUrl_test.go"
		if os.path.isfile(expected):
			os.remove(expected)
		result = generateTestFileNameForGoTest.createFromPosition(filename, position)
		testFileContent = filer2.read(result)

		expectedText = """package elit
import (
    "my"
	"testing"
)

func Test_doAllForMiByUrl(t *testing.T) {
    var (
	

	url string
	expected menuItem
	t *testing.T


        )
    doAllForMiByUrl(url,expected,t)
    
}"""


		assertMy.equals(result, expected)
		assertMy.equals(testFileContent, expectedText)
	def test_testName(self):
		color.blue("test here baby")
		inputText = """if inlist:
			print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
			color.red('inlist')
			print(inlist)
			print('*****************************************************************')
			currentIndex = allList.index(current) #todo: make test to test when current item not in list
			chooseNumber =  currentIndex + 1
			if chooseNumber >= len(allList):"""
		filename = os.path.join(currentFolder, 'files/printColor.poligon')

		filer.write(filename, inputText)

		clear.pyFile(filename)
		result = filer.read(filename)
		
		expected = """if inlist:
			currentIndex = allList.index(current) #todo: make test to test when current item not in list
			chooseNumber =  currentIndex + 1
			if chooseNumber >= len(allList):"""
		print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
		color.red('expected')
		print(expected)
		print('*****************************************************************')	
		self.assertEqual(result, expected)
Пример #5
0
def filename2(filename, obj):

    data = filer.read(filename)

    color.red("obj")
    print(repr(obj))

    regex = "(\S+) as " + obj

    color.red("regex")
    print(repr(regex))

    m = re.findall(regex, data)
    match = len(m)
    if match:
        obj = m[0]

    # folder = os.path.join(os.path.dirname(filename), obj+ '.py')
    rel2 = "./" + obj
    filename2 = absRel.AbsAddExtension(filename, rel2)
    if not os.path.isfile(filename2):
        regex2 = "sys.path.insert\(0, '(.+)'\)"
        matches = re.findall(regex2, data)
        for m in matches:
            filename2 = os.path.join(m, obj + ".py")
            if os.path.isfile(filename2):
                break
    if not os.path.isfile(filename2):
        filename2 = filename
    return filename2
	def test_testName(self):
		color.blue("test here baby")
		filename = os.path.abspath(os.path.join(currentFolder, '../../makeTestForGo/test/createFileName1_test/deep/deep/deep/a.py'))
		position = 10

		testFile = forPy.createFromPosition(filename, position)

		 
		result = filer.read(testFile)
		expected = """import unittest
import sys
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/util')
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/makeTest/test/createFileName1_test/deep/deep/deep')
import color
import assertMy
import a

class Test(unittest.TestCase):
	def test_testName(self):
		color.blue("test here baby")
		result = a.()
		expected = ""
		assertMy.equals(result, expected)

if __name__ == '__main__':
	unittest.main()"""
		assertMy.equals(result, expected)
Пример #7
0
	def test_testName(self):
		color.blue("test here baby")
		inputText = """
	def test_testName(self):
		color.blue("test here baby")
		intpuText = 
		beatyModel.py(inputText)	
	def test_testName(self):
		color.blue("test here baby")
		intpuText = 
		beatyModel.py(inputText)"""
		filename = os.path.join(currentFolder, 'files/poligon')
		filer.write(filename, inputText)
		expected = """\tdef test_testName(self):
		color.blue("test here baby")
		intpuText = 
		beatyModel.py(inputText)


	def test_testName(self):
		color.blue("test here baby")
		intpuText = 
		beatyModel.py(inputText)
		"""
		beatyModel.pyFile(filename)	
		result = filer.read(filename)
		color.red("inputText")
		print(repr(inputText))
		print(inputText)
		assertMy.stringDiffByLines(result, expected)
Пример #8
0
def fileNameAndPositionTo_goRunTestCommand(fileName, position):
    fileText = filer.read(fileName)
    methodName=getMethodNameGo(fileText, position)

    dirName = os.path.dirname(fileName)
    command = "cd \"{}\"; TALK=1 {}".format( dirName, getCommandLineStringForGoTestThisMethod(methodName))

    return command
Пример #9
0
def getPosition(filename2, regex):
    
    position2 = 0
    data2 = filer.read(filename2)
    finditer = re.finditer(regex, data2)
    indexes = [m.start(0) for m in finditer]
    if len(indexes):
        position2 = indexes[0]
    return position2        
Пример #10
0
def createFromPosition(filename, position):
	### read from file ###
	text = filer2.read(filename)
	### get method name ###
	methodName = navigateToModel.method(text, position)
	color.red('methodName')
	print(repr(methodName))
	### generate test file and write it to disk ###
	return create(filename, methodName)
	def test_testName(self):
		color.blue("test here baby")
		filename = '/Users/maks/testPoligon/a.py'

		testFile = forPy.create(filename, "method")
		result = filer.read(testFile)


		assertMy.equals(result, expected)
Пример #12
0
def filenameAndPositionTransform(filename, position):
     
    ext = filename.split('.')[-1]    

    isPy = ext == 'py'
   
    text = filer.read(filename)
    
    filename2 = filename
    position2 = 0

    color.red('text')
    print(text)

    color.red('position')
    print(repr(position))

    [obj, method] = getObject(text, position)

    color.red('obj')
    print(repr(obj))
    color.red('method')
    print(repr(method))
    
    if isPy:
        filename2 = pyFind.filename2(filename, obj)
        color.red('filename2')
        print(repr(filename2))
        if method:
            regex = "def {0}\(|{0} =".format(method)
            color.red('regex')
            print(repr(regex))
            position2 = getPosition(filename2, regex) 
            if position2 > 0:
                position2 = position2 + len("def")
    else:
        if obj:
            color.red('text')
            print(text)
            color.red('obj')
            print(repr(obj))
            rel = findRequire(text, obj)
            color.red('rel')
            print(repr(rel))

            filename2 = absRel.AbsAddExtension(filename, rel)

        regex = method + ' = '
        position2 = getPosition(filename2, regex)




    
            
    return (filename2, position2)    
	def test_testName(self):
		color.blue("test here baby")
		inputText = """import sublime
import sublime_plugin
import os
from os import listdir
from os.path import isfile, join
import sys
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/goodPath')

import findAllRelative_model
class repaire_relative_paths_plugin_Command(sublime_plugin.WindowCommand):
    def run(self):
       print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
       print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
       print("new run repaire_relative_paths_plugin_")
       print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
       print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
       window = self.window
       view = window.active_view()
       filename = view.file_name()
       findAllRelative_model.goAndWrite(filename)
       sublime.status_message("repaire_relative_paths_plugin done")
       


"""
		filename = os.path.join(currentFolder, 'files/printColor.poligon')

		filer.write(filename, inputText)

		clear.pyFile(filename)
		result = filer.read(filename)
		
		color.red('result')
		print(repr(result))

		expected = """import sublime
import sublime_plugin
import os
from os import listdir
from os.path import isfile, join
import sys
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/goodPath')
import findAllRelative_model
class repaire_relative_paths_plugin_Command(sublime_plugin.WindowCommand):
    def run(self):
       window = self.window
       view = window.active_view()
       filename = view.file_name()
       findAllRelative_model.goAndWrite(filename)
       sublime.status_message("repaire_relative_paths_plugin done")"""
		color.red('expected')
		print(expected)
		
		assertMy.stringDiffByLines(result, expected	)
def writeTestFileBySourceFileTargetAndPosition(targetFileName, position):
    ### read target file name ###
    targetFileContent = filer2.read(targetFileName)
    ### generate test file content by targetFileContent and position ###
    testFileContent = createTestFileContentBySourceFileTargetAndPosition(targetFileContent, position)
    color.red("testFileContent")
    print(testFileContent)

    methodName = getMethodNameByFileContentAndPosition(targetFileContent, position)
    return create(targetFileName, methodName, testFileContent)
Пример #15
0
	def test_testName(self):
		color.blue("test here baby")
		fileName = os.path.dirname(os.path.realpath(__file__)) + "/poligon/forGo/testable.go"
		methodName = "myMethod"
		fileContent  = filer2.read(fileName)
		
		expected = os.path.dirname(os.path.realpath(__file__)) + "/poligon/forGo/Test_myMethod_test.go"
		if os.path.isfile(expected):
			os.remove(expected)
		result = generateTestFileNameForGoTest.create(fileName, methodName, fileContent)

		assertMy.equals(result, expected)
Пример #16
0
    def test_testName(self):
        color.blue("test here baby")

        result = filer2.read(os.path.join(currentFolder, '../../find_usages_plugin.py'))

        indexes = range(638)


        for i in indexes:
            # color.red(str(i)+result[i])
            number = color.color(str(i), "red")
            char = color.color(repr(result[i]), "green")
            line = "{0} - {1}".format(number, char)
            print(line)
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
	def test_testName(self):
		color.blue("test here baby")
		expectedJsFile=os.path.join(currentFolder, 'poligon/poligon.js')
		os.remove(expectedJsFile)
		filename=os.path.join(currentFolder, 'poligon/poligon.coffee')
		coffee_compile_model.coffeeCompile(filename)
		js=filer.read(expectedJsFile).strip()
		expectedJs="""// Generated by CoffeeScript 1.8.0
var hello;

hello = function() {
  return console.log("world");
};

""".strip()
		assertMy.equals(js, expectedJs)
Пример #19
0
	def test_goAndWrite(self):
		color.blue("test here baby")
		inputFileContent = """routes = require '../../routes/e'
rrnt = require '../f.iced'
db = require 'db'
module.exports = (url, param, test)->
	rrnt routes, url, param, test
	"""	
		path = "/Users/maks/Library/Application Support/Sublime Text 3/Packages/goodPath/forTest/a/b/c/testForWrite.iced"
		filer.write(path, inputFileContent)
		findAllRelative_model.goAndWrite(path)
		expected = """routes = require '../e.iced'
rrnt = require './k/f.iced'
db = require 'db'
module.exports = (url, param, test)->
	rrnt routes, url, param, test
	"""		
		result = filer.read(path)
		self.assertEqual (result, expected)	
Пример #20
0
    def find(self, filename, position):

        text = filer2.read(filename)
        [obj, method] = navigateToModel.getObject(text, position)

        

        mypath = absRel3.folder(filename)
        
        targetFiles = []
        for (dirpath, dirnames, filenames) in walk(mypath):

            targetFiles.extend([ os.path.join(dirpath, f) for f in filenames if absRel3.Ext(f) == 'py'])

        regex = "{}.\(".format(method)
        regex = re.compile(regex)       
        
        returnList = []     
        for f in targetFiles:
            # text = filer2.read(f)
            positions = navigateToModel.getPositions(f, regex)      
            if positions:
                returnList.extend([(f, p) for p in positions])

        
        self.i.setAll(returnList)



        if returnList:
            current = returnList[-1]
            (f,p) = current
            self.i.currentSet("{0}{1}".format(f,p))
            
            count = len(returnList)
            
            status = "{0} of {1}".format(count, count)
            # current.insert(2, status)
            current += (status,)
        else:
            status = "no found"
            current = None  
        return current  
Пример #21
0
def go(filePath):
	"""Returns file content with repaired relative paths"""
	fileContent = filer.read(filePath)
	relPathList = getRel.getRel (fileContent)

	fileNames = [relPath.split("/")[-1] for relPath in relPathList]
	color.blue("fileNames")
	print(fileNames)

	futherFolder = getFutherFolder_model.get(filePath)
	absFileNames = [recursiveSearch_model.find_files(futherFolder, fileName) for fileName in fileNames]

	color.blue("absFileNames")
	print(absFileNames)

	newRelPathList = [absRel.Rel(filePath, absPath) for absPath in absFileNames]
	
	# first found would be inserted

	fileContent = replacePath.go(relPathList, newRelPathList, fileContent)
	return fileContent
	def test_testName(self):
		color.blue("test here baby")

		filename = os.path.dirname(os.path.realpath(__file__)) + "/poligion/poligonRealFromRunly.go"
		position = 461

		expected = os.path.dirname(os.path.realpath(__file__)) + "/poligion/Test_searchYoutubeByYoutubeId_test.go"

		if os.path.isfile(expected):
			os.remove(expected)
		result = generateTestFileNameForGoTest.createFromPosition(filename, position)
		testFileContent = filer2.read(result)

		expectedText = """package db
import (
    "my"
	"testing"
)

func Test_searchYoutubeByYoutubeId(t *testing.T) {
    var (
	

	youtubeId string

	onlyOne *YoutubeSearchResult

	onlyOne_expected *YoutubeSearchResult
        )
    onlyOne = searchYoutubeByYoutubeId(youtubeId)
    
	expectedJson_onlyOne := ``
	my.FromJson(expectedJson_onlyOne, &onlyOne_expected)
	my.Test(onlyOne, onlyOne_expected, t)
}"""


		assertMy.equals(result, expected)
		assertMy.equals(testFileContent, expectedText)
Пример #23
0
def doAllByFileName(fileName):
	fileContent = filer2.read (fileName)
	fileContent = fileContent.strip()
	return finalPrepare(replaceNullByErr(go(fileContent)))
Пример #24
0
 def test_zero(self):
     pos = 729
     filename = '/Users/maks/Dropbox/nodeApps/call/deleteDb.iced'
     data = filer.read(filename)
     char = data[729]
     print('char=',char)
def getPositionInSourceWhereToPaste(sourceFilename):
    fileContent_source = filer2.read(sourceFilename)
    return getPositionInSourceWhereToPaste_bySourceFileContent(fileContent_source)
Пример #26
0
def pyFile(filename):
    fileText = filer.read(filename)
    fileText = py(fileText)
    filer.write(filename, fileText)
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/navigateTo')
import pyFind
import navigateToModel

import unittest
import sys
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/util')
import color


import sys
sys.path.insert(0, '/Users/maks/Library/Application Support/Sublime Text 3/Packages/moveNearReplace')
import filer2


inputText = filer2.read('/Users/maks/Library/Application Support/Sublime Text 3/Packages/findUsages/find_usages_plugin.py')



class Test(unittest.TestCase):
    
    def test_bigFile(self):
        color.blue("test here baby")
        
        indexes = range(len(inputText))
        

        for i in indexes:


        expected = ['reactOnCursorPosition', 'starter']
Пример #28
0
def getPositions(filename, regex):
    position2 = 0
    data2 = filer.read(filename)
    finditer = re.finditer(regex, data2)
    indexes = [m.start(0) for m in finditer]
    return indexes
Пример #29
0
def fileNameToParamString(fileName):
	content = filer2.read ( fileName)
	params = getParams (content)
	string = paramsToString(params)
	return string
def main_getFuncUsageByFileNameAndPosition(filename, position):
    targetFileContent = filer2.read(filename)
    lineContent = g.getFullLineWhereCursorIs(targetFileContent, position)
    return generateFuncUsageByLineContentGo(lineContent)