mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Convert unit tests to munit
This commit is contained in:
@ -11,10 +11,10 @@ import docspell.convert.ConversionResult.Handler
|
||||
import docspell.convert.extern.{TesseractConfig, UnoconvConfig, WkHtmlPdfConfig}
|
||||
import docspell.convert.flexmark.MarkdownConfig
|
||||
import docspell.files.{ExampleFiles, TestFiles}
|
||||
import minitest.SimpleTestSuite
|
||||
import munit._
|
||||
import docspell.convert.extern.OcrMyPdfConfig
|
||||
|
||||
object ConversionTest extends SimpleTestSuite with FileChecks {
|
||||
class ConversionTest extends FunSuite with FileChecks {
|
||||
val blocker = TestFiles.blocker
|
||||
implicit val CS = TestFiles.CS
|
||||
|
||||
@ -101,59 +101,58 @@ object ConversionTest extends SimpleTestSuite with FileChecks {
|
||||
)
|
||||
|
||||
test("convert to pdf") {
|
||||
if (!commandsExist) ignore("At least one of the conversion programs not found")
|
||||
else
|
||||
File
|
||||
.withTempDir[IO](target, "convpdf")
|
||||
.use { dir =>
|
||||
conversion.use { conv =>
|
||||
def check(n: Long): Handler[IO, Unit] =
|
||||
storePdfHandler(dir.resolve(s"test-$n.pdf")).map { p =>
|
||||
assert(p.isNonEmpty && p.isPDF)
|
||||
}
|
||||
assume(commandsExist, "At least one of the conversion programs not found")
|
||||
|
||||
runConversion(pdfOnly, check, conv).compile.drain
|
||||
}
|
||||
File
|
||||
.withTempDir[IO](target, "convpdf")
|
||||
.use { dir =>
|
||||
conversion.use { conv =>
|
||||
def check(n: Long): Handler[IO, Unit] =
|
||||
storePdfHandler(dir.resolve(s"test-$n.pdf")).map { p =>
|
||||
assert(p.isNonEmpty && p.isPDF)
|
||||
}
|
||||
|
||||
runConversion(pdfOnly, check, conv).compile.drain
|
||||
}
|
||||
.unsafeRunSync()
|
||||
}
|
||||
.unsafeRunSync()
|
||||
}
|
||||
|
||||
test("convert image to pdf and txt") {
|
||||
if (!commandsExist) ignore("At least one of the conversion programs not found")
|
||||
else
|
||||
File
|
||||
.withTempDir[IO](target, "convimgpdf")
|
||||
.use { dir =>
|
||||
conversion.use { conv =>
|
||||
def check(n: Long): Handler[IO, Unit] =
|
||||
storePdfTxtHandler(dir.resolve(s"test-$n.pdf"), dir.resolve(s"test-$n.txt"))
|
||||
.map { case (p, t) =>
|
||||
assert(p.isNonEmpty && p.isPDF)
|
||||
assert(t.isNonEmpty && t.isPlainText)
|
||||
}
|
||||
assume(commandsExist, "At least one of the conversion programs not found")
|
||||
File
|
||||
.withTempDir[IO](target, "convimgpdf")
|
||||
.use { dir =>
|
||||
conversion.use { conv =>
|
||||
def check(n: Long): Handler[IO, Unit] =
|
||||
storePdfTxtHandler(dir.resolve(s"test-$n.pdf"), dir.resolve(s"test-$n.txt"))
|
||||
.map { case (p, t) =>
|
||||
assert(p.isNonEmpty && p.isPDF)
|
||||
assert(t.isNonEmpty && t.isPlainText)
|
||||
}
|
||||
|
||||
runConversion(pdfAndTxt, check, conv).compile.drain
|
||||
}
|
||||
runConversion(pdfAndTxt, check, conv).compile.drain
|
||||
}
|
||||
.unsafeRunSync()
|
||||
}
|
||||
.unsafeRunSync()
|
||||
}
|
||||
|
||||
test("do not convert image bombs") {
|
||||
if (!commandsExist) ignore("At least one of the conversion programs not found")
|
||||
else
|
||||
conversion
|
||||
.use { conv =>
|
||||
def check: Handler[IO, Unit] =
|
||||
Kleisli({
|
||||
case ConversionResult.InputMalformed(_, _) =>
|
||||
().pure[IO]
|
||||
case cr =>
|
||||
IO.raiseError(new Exception(s"Unexpected result: $cr"))
|
||||
})
|
||||
assume(commandsExist, "At least one of the conversion programs not found")
|
||||
|
||||
runConversion(bombs, _ => check, conv).compile.drain
|
||||
}
|
||||
.unsafeRunSync()
|
||||
conversion
|
||||
.use { conv =>
|
||||
def check: Handler[IO, Unit] =
|
||||
Kleisli({
|
||||
case ConversionResult.InputMalformed(_, _) =>
|
||||
().pure[IO]
|
||||
case cr =>
|
||||
IO.raiseError(new Exception(s"Unexpected result: $cr"))
|
||||
})
|
||||
|
||||
runConversion(bombs, _ => check, conv).compile.drain
|
||||
}
|
||||
.unsafeRunSync()
|
||||
}
|
||||
|
||||
def runConversion[A](
|
||||
|
@ -6,10 +6,10 @@ import cats.effect._
|
||||
import docspell.common._
|
||||
import docspell.convert._
|
||||
import docspell.files.{ExampleFiles, TestFiles}
|
||||
import minitest.SimpleTestSuite
|
||||
import munit._
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
object ExternConvTest extends SimpleTestSuite with FileChecks {
|
||||
class ExternConvTest extends FunSuite with FileChecks {
|
||||
val blocker = TestFiles.blocker
|
||||
implicit val CS = TestFiles.CS
|
||||
val utf8 = StandardCharsets.UTF_8
|
||||
@ -22,26 +22,24 @@ object ExternConvTest extends SimpleTestSuite with FileChecks {
|
||||
Seq("-s", "A4", "--encoding", "UTF-8", "-", "{{outfile}}"),
|
||||
Duration.seconds(20)
|
||||
)
|
||||
assume(commandExists(cfg.program), s"Command ${cfg.program} not found. Ignore tests.")
|
||||
File
|
||||
.withTempDir[IO](target, "wkhtmltopdf")
|
||||
.use(dir =>
|
||||
IO {
|
||||
val wkCfg = WkHtmlPdfConfig(cfg, target)
|
||||
val p =
|
||||
WkHtmlPdf
|
||||
.toPDF[IO, Path](wkCfg, 8192, utf8, SanitizeHtml.none, blocker, logger)(
|
||||
ExampleFiles.letter_de_html.readURL[IO](8192, blocker),
|
||||
storePdfHandler(dir.resolve("test.pdf"))
|
||||
)
|
||||
.unsafeRunSync()
|
||||
|
||||
if (!commandExists(cfg.program)) ignore(s"Command ${cfg.program} not found")
|
||||
else
|
||||
File
|
||||
.withTempDir[IO](target, "wkhtmltopdf")
|
||||
.use(dir =>
|
||||
IO {
|
||||
val wkCfg = WkHtmlPdfConfig(cfg, target)
|
||||
val p =
|
||||
WkHtmlPdf
|
||||
.toPDF[IO, Path](wkCfg, 8192, utf8, SanitizeHtml.none, blocker, logger)(
|
||||
ExampleFiles.letter_de_html.readURL[IO](8192, blocker),
|
||||
storePdfHandler(dir.resolve("test.pdf"))
|
||||
)
|
||||
.unsafeRunSync()
|
||||
|
||||
assert(p.isNonEmpty && p.isPDF)
|
||||
}
|
||||
)
|
||||
.unsafeRunSync()
|
||||
assert(p.isNonEmpty && p.isPDF)
|
||||
}
|
||||
)
|
||||
.unsafeRunSync()
|
||||
}
|
||||
|
||||
test("convert office to pdf") {
|
||||
@ -51,25 +49,24 @@ object ExternConvTest extends SimpleTestSuite with FileChecks {
|
||||
Duration.seconds(20)
|
||||
)
|
||||
|
||||
if (!commandExists(cfg.program)) ignore(s"Command ${cfg.program} not found")
|
||||
else
|
||||
File
|
||||
.withTempDir[IO](target, "unoconv")
|
||||
.use(dir =>
|
||||
IO {
|
||||
val ucCfg = UnoconvConfig(cfg, target)
|
||||
val p =
|
||||
Unoconv
|
||||
.toPDF[IO, Path](ucCfg, 8192, blocker, logger)(
|
||||
ExampleFiles.examples_sample_docx.readURL[IO](8192, blocker),
|
||||
storePdfHandler(dir.resolve("test.pdf"))
|
||||
)
|
||||
.unsafeRunSync()
|
||||
assume(commandExists(cfg.program), s"Command ${cfg.program} not found. Ignore tests.")
|
||||
File
|
||||
.withTempDir[IO](target, "unoconv")
|
||||
.use(dir =>
|
||||
IO {
|
||||
val ucCfg = UnoconvConfig(cfg, target)
|
||||
val p =
|
||||
Unoconv
|
||||
.toPDF[IO, Path](ucCfg, 8192, blocker, logger)(
|
||||
ExampleFiles.examples_sample_docx.readURL[IO](8192, blocker),
|
||||
storePdfHandler(dir.resolve("test.pdf"))
|
||||
)
|
||||
.unsafeRunSync()
|
||||
|
||||
assert(p.isNonEmpty && p.isPDF)
|
||||
}
|
||||
)
|
||||
.unsafeRunSync()
|
||||
assert(p.isNonEmpty && p.isPDF)
|
||||
}
|
||||
)
|
||||
.unsafeRunSync()
|
||||
}
|
||||
|
||||
test("convert image to pdf") {
|
||||
@ -78,27 +75,25 @@ object ExternConvTest extends SimpleTestSuite with FileChecks {
|
||||
Seq("{{infile}}", "out", "-l", "deu", "pdf", "txt"),
|
||||
Duration.seconds(20)
|
||||
)
|
||||
assume(commandExists(cfg.program), s"Command ${cfg.program} not found")
|
||||
File
|
||||
.withTempDir[IO](target, "tesseract")
|
||||
.use(dir =>
|
||||
IO {
|
||||
val tessCfg = TesseractConfig(cfg, target)
|
||||
val (pdf, txt) =
|
||||
Tesseract
|
||||
.toPDF[IO, (Path, Path)](tessCfg, Language.German, 8192, blocker, logger)(
|
||||
ExampleFiles.camera_letter_en_jpg.readURL[IO](8192, blocker),
|
||||
storePdfTxtHandler(dir.resolve("test.pdf"), dir.resolve("test.txt"))
|
||||
)
|
||||
.unsafeRunSync()
|
||||
|
||||
if (!commandExists(cfg.program)) ignore(s"Command ${cfg.program} not found")
|
||||
else
|
||||
File
|
||||
.withTempDir[IO](target, "tesseract")
|
||||
.use(dir =>
|
||||
IO {
|
||||
val tessCfg = TesseractConfig(cfg, target)
|
||||
val (pdf, txt) =
|
||||
Tesseract
|
||||
.toPDF[IO, (Path, Path)](tessCfg, Language.German, 8192, blocker, logger)(
|
||||
ExampleFiles.camera_letter_en_jpg.readURL[IO](8192, blocker),
|
||||
storePdfTxtHandler(dir.resolve("test.pdf"), dir.resolve("test.txt"))
|
||||
)
|
||||
.unsafeRunSync()
|
||||
|
||||
assert(pdf.isNonEmpty && pdf.isPDF)
|
||||
assert(txt.isNonEmpty && txt.isPlainText)
|
||||
}
|
||||
)
|
||||
.unsafeRunSync()
|
||||
assert(pdf.isNonEmpty && pdf.isPDF)
|
||||
assert(txt.isNonEmpty && txt.isPlainText)
|
||||
}
|
||||
)
|
||||
.unsafeRunSync()
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user