Repository navigation
Coverage round 2 batch C: AppState-constructible tests, dialog states, project load/export #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eb1c460
Make AppState constructible in tests and cover app-level glue (round …
sdercolin b281749
Fix anyDialogOpeningExceptMacroPluginManager not excluding the manager
sdercolin 600e870
Make closeAllDialogs close every dialog
sdercolin 99dd724
Surface parse errors when importing a project file
sdercolin fa8cf0f
Treat an empty output file as none in ProjectSettingDialogState
sdercolin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package io | ||
|
|
||
| import com.sdercolin.vlabeler.env.Log | ||
| import com.sdercolin.vlabeler.io.exportProject | ||
| import com.sdercolin.vlabeler.io.exportProjectModule | ||
| import com.sdercolin.vlabeler.io.singleModuleToRawLabels | ||
| import com.sdercolin.vlabeler.model.Project | ||
| import com.sdercolin.vlabeler.ui.AppState | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.SupervisorJob | ||
| import kotlinx.coroutines.cancel | ||
| import kotlinx.coroutines.runBlocking | ||
| import testutil.TestEnv | ||
| import testutil.TestFixtures | ||
| import testutil.TestLabelers | ||
| import testutil.createTestProject | ||
| import java.io.File | ||
| import kotlin.io.path.createTempDirectory | ||
| import kotlin.test.AfterTest | ||
| import kotlin.test.BeforeTest | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertTrue | ||
|
|
||
| /** | ||
| * Tests for [ProjectStore.exportProject] and [ProjectStore.exportProjectModule]: the raw label file written by the | ||
| * labeler writer, and the creation of missing output directories. | ||
| */ | ||
| class ExportProjectTest { | ||
|
|
||
| private lateinit var tempDir: File | ||
| private lateinit var sampleDir: File | ||
| private lateinit var scope: CoroutineScope | ||
| private lateinit var appState: AppState | ||
|
|
||
| @BeforeTest | ||
| fun setup() { | ||
| Log.muted = true | ||
| TestEnv.ensureLogDirectory() | ||
| scope = CoroutineScope(SupervisorJob()) | ||
| tempDir = createTempDirectory("vlabeler-test").toFile() | ||
| sampleDir = TestFixtures.deploy( | ||
| "oto", | ||
| tempDir.resolve("oto"), | ||
| wavFiles = listOf("_a_ka.wav"), | ||
| ) | ||
| appState = testutil.TestAppState.create(scope = scope) | ||
| } | ||
|
|
||
| @AfterTest | ||
| fun teardown() { | ||
| scope.cancel() | ||
| Log.muted = false | ||
| tempDir.deleteRecursively() | ||
| } | ||
|
|
||
| private fun createProject(): Project = createTestProject( | ||
| labeler = TestLabelers.utauOto, | ||
| sampleDirectory = sampleDir, | ||
| inputFilePath = sampleDir.resolve("oto.ini").absolutePath, | ||
| ) | ||
|
|
||
| @Test | ||
| fun testExportProjectModuleWritesRawLabels() { | ||
| val project = createProject() | ||
| val output = tempDir.resolve("out/exported.ini") | ||
|
|
||
| runBlocking { appState.exportProjectModule(project, moduleIndex = 0, outputFile = output) } | ||
|
|
||
| // parent directory is created on demand | ||
| assertTrue(output.parentFile.isDirectory) | ||
| val expected = project.singleModuleToRawLabels(0) | ||
| assertEquals(expected, output.readText()) | ||
| assertTrue(output.readText().isNotBlank()) | ||
| } | ||
|
|
||
| @Test | ||
| fun testExportProjectWritesToModuleRawFile() { | ||
| val project = createProject() | ||
| val rawFile = requireNotNull(project.modules[0].getRawFile(project)) | ||
|
|
||
| runBlocking { appState.exportProject(project) } | ||
|
|
||
| val expected = project.singleModuleToRawLabels(0) | ||
| assertEquals(expected, rawFile.readText()) | ||
| } | ||
|
|
||
| @Test | ||
| fun testExportProjectSkipsModulesWithoutRawFile() { | ||
| // a module whose rawFilePath is null must be skipped without error | ||
| val project = createProject() | ||
| val withoutRaw = project.copy( | ||
| modules = project.modules.map { it.copy(rawFilePath = null) }, | ||
| ) | ||
|
|
||
| // no exception thrown and nothing written | ||
| runBlocking { appState.exportProject(withoutRaw) } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.