예제 #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)
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
def test():
    assert c.commentsHashtag(lines) == {(1,): [['Un commentaire normal'], 1], (2,): [['avec un com à la fin'], 1]}
    assert c.commentBlocks(lines) == {(3, 4): [[' un commentaire en block', 'ca continue'], 35]}
    assert c.commentCount(lines) == (3, {(1,): [['Un commentaire normal'], 1], (2,): [['avec un com à la fin'], 1], (3, 4): [[' un commentaire en block', 'ca continue'], 35]})
    assert c.detectCom(lines[0]) == 0
    assert c.detectCom(lines[1]) == 1
    assert c.detectCom(lines[2]) == 19
    assert c.detectCom(lines[3]) == -1
    assert c.detectCom(lines[4]) == 0
    assert c.detectCom(lines[5]) == -2
    assert c.retirerCom(lines) == ['Une ligne qui sert à rien', '', 'une ligne inutile ']
    assert c.analyseCom(lines) == ([0, 21, 20, 24, 11, 0], 0.2824427480916031, 0.6666666666666666, 3)
    assert c.howCommented(lines) == (True, (12.666666666666666, 9.792287214378922), (0.6666666666666666, 0.2824427480916031))
    assert c.commentsWords(lines) == ({'un': 3, 'commentaire': 2}, ['normalavec', 'com', 'à', 'la', 'fin', 'en', 'blockca', 'continue'])
    assert c.isFrancais('bonjour', motsDecode)
    assert not c.isFrancais('aoriezur', motsDecode)
    assert c.ratioFrancais(lines) == (1.0, 0.625)
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)
예제 #10
0

print('Nom du fichier à analyser :')

#On rentre le fichier que l'on veut manipuler
path = input()
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.
예제 #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,
예제 #12
0
import trouve_fonction
import commentaires
import checkIndentation


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("testTim/event_candidate_a.rb.rb")
testFonction2=readLines("testTim/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, 'nom': 'appointment?', 'end': 37}, {'start': 39, 'longueur': 7, 'nom': 'self.availabilities', 'end': 47}, {'start': 50, 'longueur': 3, 'nom': 'starts_at_cannot_be_greater_than_ends_at', 'end': 54}, {'start': 56, 'longueur': 3, 'nom': 'ends_at_cannot_be_a_different_day_than_starts_at', 'end': 60}, {'start': 62, 'longueur': 5, 'nom': 'hours_must_be_a_multiple_of_thirty_minutes', 'end': 68}, {'start': 70, 'longueur': 4, 'nom': 'same_kind_of_event_cannot_be_in_a_same_time_slot', 'end': 75}, {'start': 77, 'longueur': 4, 'nom': 'appointment_cannot_be_outside_of_opening_hours', 'end': 82}, {'start': 84, 'longueur': 4, 'nom': 'self.slots_available', 'end': 89}, {'start': 91, 'longueur': 9, 'nom': 'self.split_into_slots', 'end': 101}]
    assert trouve_fonction.count_fonction(testFonction2)==[]
    assert trouve_fonction.count_fonction(testFonction3)[:6]=="Erreur"