[skip ci] Formatting

This commit is contained in:
Syer10
2024-09-03 21:37:18 -04:00
parent e968a2195a
commit 6c1fbfa63b
220 changed files with 2493 additions and 2519 deletions
@@ -40,7 +40,8 @@ class CloudFlareTest {
}
nhentai =
Source.getSourceList()
Source
.getSourceList()
.firstNotNullOf { it.id.toLong().takeIf { it == 3122156392225024195L } }
.let(GetCatalogueSource::getCatalogueSourceOrNull) as HttpSource
}
@@ -81,23 +81,25 @@ class TestExtensionCompatibility {
runBlocking(Dispatchers.Default) {
val semaphore = Semaphore(10)
val popularCount = AtomicInteger(1)
sources.map { source ->
async {
semaphore.withPermit {
logger.info { "${popularCount.getAndIncrement()} - Now fetching popular manga from $source" }
try {
mangaToFetch += source to (
repeat { source.getPopularManga(1) }
.mangas.firstOrNull()
?: throw Exception("Source returned no manga")
)
} catch (e: Exception) {
logger.warn { "Failed to fetch popular manga from $source: ${e.message}" }
failedToFetch += source to e
sources
.map { source ->
async {
semaphore.withPermit {
logger.info { "${popularCount.getAndIncrement()} - Now fetching popular manga from $source" }
try {
mangaToFetch += source to (
repeat { source.getPopularManga(1) }
.mangas
.firstOrNull()
?: throw Exception("Source returned no manga")
)
} catch (e: Exception) {
logger.warn { "Failed to fetch popular manga from $source: ${e.message}" }
failedToFetch += source to e
}
}
}
}
}.awaitAll()
}.awaitAll()
File("$BASE_PATH/failedToFetch.txt").writeText(
failedToFetch.joinToString("\n") { (source, exception) ->
"${source.name} (${source.lang.uppercase()}, ${source.id}):" +
@@ -107,24 +109,25 @@ class TestExtensionCompatibility {
logger.info { "Now fetching manga info from ${mangaToFetch.size} sources" }
val mangaCount = AtomicInteger(1)
mangaToFetch.map { (source, manga) ->
async {
semaphore.withPermit {
logger.info { "${mangaCount.getAndIncrement()} - Now fetching manga from $source" }
try {
manga.copyFrom(repeat { source.getMangaDetails(manga) })
manga.initialized = true
} catch (e: Exception) {
logger.warn {
"Failed to fetch manga info from $source for ${manga.title} (${source.mangaDetailsRequest(
manga,
).url}): ${e.message}"
mangaToFetch
.map { (source, manga) ->
async {
semaphore.withPermit {
logger.info { "${mangaCount.getAndIncrement()} - Now fetching manga from $source" }
try {
manga.copyFrom(repeat { source.getMangaDetails(manga) })
manga.initialized = true
} catch (e: Exception) {
logger.warn {
"Failed to fetch manga info from $source for ${manga.title} (${source.mangaDetailsRequest(
manga,
).url}): ${e.message}"
}
mangaFailedToFetch += Triple(source, manga, e)
}
mangaFailedToFetch += Triple(source, manga, e)
}
}
}
}.awaitAll()
}.awaitAll()
File("$BASE_PATH/MangaFailedToFetch.txt").writeText(
mangaFailedToFetch.joinToString("\n") { (source, manga, exception) ->
"${source.name} (${source.lang}, ${source.id}):" +
@@ -135,35 +138,40 @@ class TestExtensionCompatibility {
logger.info { "Now fetching manga chapters from ${mangaToFetch.size} sources" }
val chapterCount = AtomicInteger(1)
mangaToFetch.filter { it.second.initialized }.map { (source, manga) ->
async {
semaphore.withPermit {
logger.info { "${chapterCount.getAndIncrement()} - Now fetching manga chapters from $source" }
try {
chaptersToFetch +=
Triple(
source,
manga,
repeat { source.getChapterList(manga) }.firstOrNull() ?: throw Exception("Source returned no chapters"),
)
} catch (e: Exception) {
logger.warn {
"Failed to fetch manga chapters from $source for ${manga.title} (${source.mangaDetailsRequest(
manga,
).url}): ${e.message}"
mangaToFetch
.filter { it.second.initialized }
.map { (source, manga) ->
async {
semaphore.withPermit {
logger.info { "${chapterCount.getAndIncrement()} - Now fetching manga chapters from $source" }
try {
chaptersToFetch +=
Triple(
source,
manga,
repeat {
source.getChapterList(manga)
}.firstOrNull()
?: throw Exception("Source returned no chapters"),
)
} catch (e: Exception) {
logger.warn {
"Failed to fetch manga chapters from $source for ${manga.title} (${source.mangaDetailsRequest(
manga,
).url}): ${e.message}"
}
chaptersFailedToFetch += Triple(source, manga, e)
} catch (e: NoClassDefFoundError) {
logger.warn {
"Failed to fetch manga chapters from $source for ${manga.title} (${source.mangaDetailsRequest(
manga,
).url}): ${e.message}"
}
chaptersFailedToFetch += Triple(source, manga, e)
}
chaptersFailedToFetch += Triple(source, manga, e)
} catch (e: NoClassDefFoundError) {
logger.warn {
"Failed to fetch manga chapters from $source for ${manga.title} (${source.mangaDetailsRequest(
manga,
).url}): ${e.message}"
}
chaptersFailedToFetch += Triple(source, manga, e)
}
}
}
}.awaitAll()
}.awaitAll()
File("$BASE_PATH/ChaptersFailedToFetch.txt").writeText(
chaptersFailedToFetch.joinToString("\n") { (source, manga, exception) ->
@@ -174,23 +182,24 @@ class TestExtensionCompatibility {
)
val pageListCount = AtomicInteger(1)
chaptersToFetch.map { (source, manga, chapter) ->
async {
semaphore.withPermit {
logger.info { "${pageListCount.getAndIncrement()} - Now fetching page list from $source" }
try {
repeat { source.getPageList(chapter) }
} catch (e: Exception) {
logger.warn {
"Failed to fetch manga info from $source for ${manga.title} (${source.mangaDetailsRequest(
manga,
).url}): ${e.message}"
chaptersToFetch
.map { (source, manga, chapter) ->
async {
semaphore.withPermit {
logger.info { "${pageListCount.getAndIncrement()} - Now fetching page list from $source" }
try {
repeat { source.getPageList(chapter) }
} catch (e: Exception) {
logger.warn {
"Failed to fetch manga info from $source for ${manga.title} (${source.mangaDetailsRequest(
manga,
).url}): ${e.message}"
}
chaptersPageListFailedToFetch += Triple(source, manga to chapter, e)
}
chaptersPageListFailedToFetch += Triple(source, manga to chapter, e)
}
}
}
}.awaitAll()
}.awaitAll()
File("$BASE_PATH/ChapterPageListFailedToFetch.txt").writeText(
chaptersPageListFailedToFetch.joinToString("\n") { (source, manga, exception) ->
@@ -34,7 +34,11 @@ class RequestParserTest {
every { ctx.formParam("map") } returns """{ "0": ["variables.file"] }"""
every { ctx.uploadedFile("0") } returns
UploadedFile(
ByteArrayInputStream(byteArrayOf()), "", "", "", 0,
ByteArrayInputStream(byteArrayOf()),
"",
"",
"",
0,
)
val test = requestParser.parseRequest(ctx)
assertIs<GraphQLRequest>(test)
@@ -57,7 +61,11 @@ class RequestParserTest {
every { ctx.formParam("map") } returns """{ "test": ["variables.file"] }"""
every { ctx.uploadedFile("test") } returns
UploadedFile(
ByteArrayInputStream(byteArrayOf()), "", "", "", 0,
ByteArrayInputStream(byteArrayOf()),
"",
"",
"",
0,
)
val test = requestParser.parseRequest(ctx)
assertIs<GraphQLRequest>(test)
@@ -83,11 +91,19 @@ class RequestParserTest {
""".trimIndent()
every { ctx.uploadedFile("test") } returns
UploadedFile(
ByteArrayInputStream(byteArrayOf()), "", "", "", 0,
ByteArrayInputStream(byteArrayOf()),
"",
"",
"",
0,
)
every { ctx.uploadedFile("test2") } returns
UploadedFile(
ByteArrayInputStream(byteArrayOf()), "", "", "", 0,
ByteArrayInputStream(byteArrayOf()),
"",
"",
"",
0,
)
val test = requestParser.parseRequest(ctx)
assertIs<GraphQLRequest>(test)
@@ -63,16 +63,16 @@ internal class UpdateControllerTest : ApplicationTest() {
assertEquals(3, updater.status.value.numberOfJobs)
}
private fun createLibraryManga(_title: String): Int {
return transaction {
MangaTable.insertAndGetId {
it[title] = _title
it[url] = _title
it[sourceReference] = 1
it[inLibrary] = true
}.value
private fun createLibraryManga(_title: String): Int =
transaction {
MangaTable
.insertAndGetId {
it[title] = _title
it[url] = _title
it[sourceReference] = 1
it[inLibrary] = true
}.value
}
}
@AfterEach
internal fun tearDown() {
@@ -35,7 +35,9 @@ import kotlin.test.assertEquals
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SearchTest : ApplicationTest() {
class FakeSearchableSource(id: Long) : StubSource(id) {
class FakeSearchableSource(
id: Long,
) : StubSource(id) {
var mangas: List<SManga> = emptyList()
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getSearchManga"))
@@ -43,9 +45,7 @@ class SearchTest : ApplicationTest() {
page: Int,
query: String,
filters: FilterList,
): Observable<MangasPage> {
return Observable.just(MangasPage(mangas, false))
}
): Observable<MangasPage> = Observable.just(MangasPage(mangas, false))
}
private val sourceId = 1L
@@ -77,12 +77,12 @@ class SearchTest : ApplicationTest() {
@Suppress("UNCHECKED_CAST")
class FilterListTest : ApplicationTest() {
open class EmptyFilterListSource(id: Long) : StubSource(id) {
open class EmptyFilterListSource(
id: Long,
) : StubSource(id) {
open var mFilterList = FilterList()
override fun getFilterList(): FilterList {
return mFilterList
}
override fun getFilterList(): FilterList = mFilterList
}
@Test
@@ -98,18 +98,37 @@ class FilterListTest : ApplicationTest() {
)
}
class FilterListSource(id: Long) : EmptyFilterListSource(id) {
class SelectFilter(name: String, values: Array<String>) : Filter.Select<String>(name, values)
class FilterListSource(
id: Long,
) : EmptyFilterListSource(id) {
class SelectFilter(
name: String,
values: Array<String>,
) : Filter.Select<String>(name, values)
class TextFilter(name: String) : Filter.Text(name)
class TextFilter(
name: String,
) : Filter.Text(name)
class TestCheckBox(name: String) : Filter.CheckBox(name, false)
class TestCheckBox(
name: String,
) : Filter.CheckBox(name, false)
class TriState(name: String, state: Int) : Filter.TriState(name, state)
class TriState(
name: String,
state: Int,
) : Filter.TriState(name, state)
class Group(name: String, state: List<TestCheckBox>) : Filter.Group<TestCheckBox>(name, state)
class Group(
name: String,
state: List<TestCheckBox>,
) : Filter.Group<TestCheckBox>(name, state)
class Sort(name: String, values: Array<String>, state: Selection) : Filter.Sort(name, values, state)
class Sort(
name: String,
values: Array<String>,
state: Selection,
) : Filter.Sort(name, values, state)
override var mFilterList =
FilterList(
@@ -319,14 +338,13 @@ class FilterListTest : ApplicationTest() {
companion object {
private var sourceCount = 0L
private fun registerSource(sourceClass: KClass<*>): EmptyFilterListSource {
return synchronized(sourceCount) {
private fun registerSource(sourceClass: KClass<*>): EmptyFilterListSource =
synchronized(sourceCount) {
val source = sourceClass.primaryConstructor!!.call(sourceCount) as EmptyFilterListSource
registerCatalogueSource(sourceCount to source)
sourceCount++
source
}
}
@AfterAll
fun teardown() {
@@ -102,7 +102,5 @@ class PaginatedListTest : ApplicationTest() {
private fun listIndicesOf(
first: Int,
last: Int,
): List<Int> {
return (first until last).toList()
}
): List<Int> = (first until last).toList()
}
@@ -31,25 +31,24 @@ fun setLoggingEnabled(enabled: Boolean = true) {
const val BASE_PATH = "build/tmp/TestDesk"
fun createLibraryManga(_title: String): Int {
return transaction {
MangaTable.insertAndGetId {
it[title] = _title
it[url] = _title
it[sourceReference] = 1
it[inLibrary] = true
}.value
fun createLibraryManga(_title: String): Int =
transaction {
MangaTable
.insertAndGetId {
it[title] = _title
it[url] = _title
it[sourceReference] = 1
it[inLibrary] = true
}.value
}
}
fun createSMangas(count: Int): List<SManga> {
return (0 until count).map {
fun createSMangas(count: Int): List<SManga> =
(0 until count).map {
SManga.create().apply {
title = "Manga $it"
url = "https://$title"
}
}
}
fun createChapters(
mangaId: Int,