コード例 #1
0
def test_appelvar():
    lines = readLines(path)
    lines = retirerCom(lines)
    lines = retirerIndentation(lines)
    result = appelvariable.appelvar(lines)
    assert type(result) == int
    assert result != 0
コード例 #2
0
def test_textefonctions():  #seul qui marche......
    lines = readLines(path)
    lines = retirerCom(lines)
    lines = retirerIndentation(lines)
    result = appelvariable.textefonctions(lines)
    assert type(result) == list
    assert result[0][0] == 38  #la premiere fonction commence ligne 38
コード例 #3
0
def test_varglobefore():
    lines = readLines(path)
    lines = retirerCom(lines)
    lines = retirerIndentation(lines)
    result_1 = appelvariable.varglobefore(1, lines)
    assert type(result_1) == list
    assert result_1 == []
コード例 #4
0
def test_varglobal():
    lines = readLines(path)
    lines = retirerCom(lines)
    lines = retirerIndentation(lines)
    result = appelvariable.varglobal(lines)
    assert type(result) == list
    assert result[0] == ["self.table_name", 2]
コード例 #5
0
def controle_duplication(Code, precision, code_controle):
    Code = checkIndentation.retirerIndentation(
        commentaires.retirerCom(Code))  #on enlève indentation et commentaires
    code_controle = checkIndentation.retirerIndentation(
        commentaires.retirerCom(code_controle))
    Code = trouve_variables.snailVariables(
        Code, trouve_variables.countVariables(Code))  #on enlève les variables
    code_controle = trouve_variables.snailVariables(
        code_controle, trouve_variables.countVariables(code_controle))
    similitude_fonctions = []
    fonctions = trouve_fonction.count_fonction(
        Code)  #trouve les fonctions de code
    for num_fonction in range(len(fonctions)):
        similitude_fonctions.append(
            controle_duplicat_fonction(
                Code[fonctions[num_fonction]["start"] +
                     1:fonctions[num_fonction]["end"]], precision,
                code_controle))
    return (similitude_fonctions)
コード例 #6
0
def fonction_double(Code, precision):
    Code = checkIndentation.retirerIndentation(
        commentaires.retirerCom(Code))  #on enlève indentation et commentaires
    Code = trouve_variables.snailVariables(
        Code, trouve_variables.countVariables(Code))  #on enlève les variables
    liste_fonction = trouve_fonction.count_fonction(Code)
    for f in range(len(liste_fonction)):
        liste_fonction[f]["copie"] = len(
            duplicationFonction.controle_duplicat_fonction(
                Code[liste_fonction[f]["start"] + 1:liste_fonction[f]["end"]],
                precision, Code[:liste_fonction[f]["start"] + 1] +
                Code[liste_fonction[f]["end"] + 1:]))
    return (liste_fonction)
コード例 #7
0
def test_numlignevarglo():
    lines = readLines(path)
    lines = retirerCom(lines)
    lines = retirerIndentation(lines)
    result = appelvariable.numlignevarglo(lines)
    assert type(result) == list
    for i in [
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
            20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
            37
    ]:
        assert i in result
    for i in [38, 39, 40]:
        assert not i in result
コード例 #8
0
def double_fonction_meme_nom(Code):
    Code = checkIndentation.retirerIndentation(
        commentaires.retirerCom(Code))  #on enlève indentation et commentaires
    Code = trouve_variables.snailVariables(
        Code, trouve_variables.countVariables(Code))  #on enlève les variables
    liste_fonction = trouve_fonction.count_fonction(Code)
    for i in range(len(liste_fonction) - 1):
        for j in range(i + 1, len(liste_fonction)):
            if liste_fonction[i]["nom"] == liste_fonction[j]["nom"]:
                liste_fonction[i]["copie_status"].append(
                    (j,
                     ressamblance_fonction(
                         Code[liste_fonction[i]["start"] +
                              1:liste_fonction[i]["end"]],
                         Code[liste_fonction[j]["start"] +
                              1:liste_fonction[j]["end"]])))
                liste_fonction[j]["copie_status"].append(
                    (i,
                     ressamblance_fonction(
                         Code[liste_fonction[i]["start"] +
                              1:liste_fonction[i]["end"]],
                         Code[liste_fonction[j]["start"] +
                              1:liste_fonction[j]["end"]])))
    return (liste_fonction)
コード例 #9
0
def test_retirerIndentation():
    assert toTest.retirerIndentation(["    mot"]) == ["mot"]
    assert toTest.retirerIndentation(["mot"]) == ["mot"]
    assert toTest.retirerIndentation(["mot    "]) == ["mot    "]
コード例 #10
0
lines = readLines(path)

#String qui représente le contenu du fichier results.txt qui sera fournis à l'interface graphique
results_txt = ""

#Affichage d'informations sur les commentaires puis suppression des commentaires.
print("----- COMMENTAIRES -----")
txt, points_c, a = printCom(lines)
results_txt = results_txt + str(txt)
lines = retirerCom(lines)

#Extraction et retrait des indentations et affichage d'informations sur la correction des indentations.
print("----- INDENTATIONS -----")
txt, points_i = printIndentation(lines)
results_txt = results_txt + txt
lines = retirerIndentation(lines)

#Parsing des fonctions présentes dans le code et affichage de leur nombre de lignes.
print("----- FONCTIONS  -----")
txt, points_f1 = printFonction(lines)
results_txt = results_txt + txt
txt, points_f2 = creation_string(lines)
results_txt = results_txt + txt

#Parsing des tests présents dans le code et affichage de données à leur sujet.
print("----- VERIFICATION DES TESTS  -----")
txt, points_t = printStatsTests(lines, False)
results_txt = results_txt + txt

#Parsing des variables présentes dans le code et affichage d'informations à leur sujet.
print("----- VARIABLES  -----")
コード例 #11
0
def readLines(l):  # retire les '/n' d'un fichier texte
    L = []
    fp = open(l, 'r')
    lines = fp.readlines()
    for line in lines:
        line = line.replace('\n', '')
        L.append(line)
    return L


testFonction1 = readLines("event_candidate_a.rb.rb")
testFonction2 = readLines("event_candidate_a_test.rb.rb")
testFonction3 = ["akmdf", "  def rpsafk", "def u", "end"]

testFonction1 = checkIndentation.retirerIndentation(
    commentaires.retirerCom(testFonction1))
testFonction2 = checkIndentation.retirerIndentation(
    commentaires.retirerCom(testFonction2))
testFonction3 = checkIndentation.retirerIndentation(
    commentaires.retirerCom(testFonction3))


def testCountFonction():
    assert trouve_fonction.count_fonction(testFonction1) == [{
        'start': 31,
        'longueur': 1,
        'nom': 'opening?',
        'end': 33
    }, {
        'start': 35,
        'longueur': 1,