forked from sourcerer-io/sourcerer-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: python list comprehension fact (sourcerer-io#117) (sourcerer-io…
…#158) * feat: python list comprehesion fact * feat: syntax stats facts * wip: fix pr
- Loading branch information
1 parent
74fd2db
commit d4a6d02
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
package test.tests.hashers | ||
|
||
import app.api.MockApi | ||
import app.extractors.Extractor | ||
import app.hashers.CommitHasher | ||
import app.hashers.CommitCrawler | ||
import app.model.* | ||
|
@@ -13,6 +14,7 @@ import org.eclipse.jgit.api.Git | |
import org.jetbrains.spek.api.Spek | ||
import org.jetbrains.spek.api.dsl.given | ||
import org.jetbrains.spek.api.dsl.it | ||
import test.utils.TestRepo | ||
import java.io.File | ||
import java.util.stream.StreamSupport.stream | ||
import kotlin.streams.toList | ||
|
@@ -236,5 +238,64 @@ class CommitHasherTest : Spek({ | |
} | ||
}*/ | ||
|
||
given("commits with syntax stats") { | ||
|
||
val lines = listOf("x = [i**2 for i range(9999)]", "def fn()", "x = 1", | ||
"x = map(lambda x: x**2, range(9999))", | ||
"x = map(lambda x: x**2, map(lambda x: x**3, range(10))", | ||
"x = map(lambda x: x**2, range(10))," + | ||
"map(lambda x: x**3, range(10)))") | ||
|
||
val authorEmail = "[email protected]" | ||
val author = Author("Test", authorEmail) | ||
|
||
val testRepoPath = "../testrepo-commit-hasher-" | ||
val testRepo = TestRepo(testRepoPath + "python-facts") | ||
|
||
val emails = hashSetOf(authorEmail) | ||
val mockApi = MockApi(mockRepo = repo) | ||
val observable = CommitCrawler.getObservable(testRepo.git, repo) | ||
|
||
it("sends stats") { | ||
for (i in 0..lines.size - 1) { | ||
val line = lines[i] | ||
val fileName = "file$i.py" | ||
testRepo.createFile(fileName, listOf(line)) | ||
testRepo.commit(message = "$line in $fileName", author = author) | ||
} | ||
|
||
val errors = mutableListOf<Throwable>() | ||
|
||
val rehashes = (0..lines.size - 1).map { "r$it" } | ||
|
||
CommitHasher(repo, mockApi, rehashes, emails) | ||
.updateFromObservable(observable, { e -> errors.add(e) }) | ||
if (errors.size > 0) { | ||
println(errors[0].message) | ||
} | ||
assertEquals(0, errors.size) | ||
|
||
val syntaxStats = mockApi.receivedAddedCommits | ||
.fold(mutableListOf<CommitStats>()) { allStats, commit -> | ||
allStats.addAll(commit.stats) | ||
allStats | ||
}.filter { it.type == Extractor.TYPE_SYNTAX } | ||
|
||
val mapStats = syntaxStats.filter { it.tech == "python>map" } | ||
val listStats = syntaxStats.filter { it.tech == "python>list" } | ||
assertEquals(3, mapStats.size) | ||
assertEquals(1, listStats.size) | ||
assertEquals(5, mapStats.map { it.numLinesAdded }.sum()) | ||
assertEquals(0, mapStats.map { it.numLinesDeleted }.sum()) | ||
|
||
assertEquals(1, listStats.map { it.numLinesAdded }.sum()) | ||
assertEquals(0, listStats.map { it.numLinesDeleted }.sum()) | ||
} | ||
|
||
afterGroup { | ||
testRepo.destroy() | ||
} | ||
} | ||
|
||
cleanRepos() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,4 +369,5 @@ class FactHasherTest : Spek({ | |
testRepo.destroy() | ||
} | ||
} | ||
|
||
}) |