<commit_before>﻿namespace Muffin.Pictures.Archiver.Tests

open Swensen.Unquote
open NUnit.Framework
open FSharp.Data

open Muffin.Pictures.Archiver.Tests.TestHelpers
open Muffin.Pictures.Archiver.Domain

module TagRetriever =
    open System.Diagnostics

    type Tags = JsonProvider<"example_exiftool_output.json">

    let callExifTool exifTool folder =
        let processStartInfo = new ProcessStartInfo()
        processStartInfo.FileName <- exifTool
        processStartInfo.Arguments <- sprintf "-fast22 -m -q -j -d \"%%Y.%%m.%%d %%H:%%M:%%S\" %s" folder
        processStartInfo.CreateNoWindow <- true
        processStartInfo.UseShellExecute <- false
        processStartInfo.RedirectStandardOutput <- true
        processStartInfo.RedirectStandardError <- true
        processStartInfo.RedirectStandardInput <- true
        let exifProcess = Process.Start(processStartInfo)
        let builder = new System.Text.StringBuilder()
        exifProcess.OutputDataReceived.Add(fun e ->
            builder.AppendLine(e.Data) |> ignore)
        exifProcess.BeginOutputReadLine()
        exifProcess.WaitForExit()
        let json = builder.ToString()
        json

module TagTests =
    open TagRetriever
    open System.IO

    let private location name =
        System.Reflection.Assembly.GetExecutingAssembly().Location
        |> Directory.GetParent
        |> fun dir -> Path.Combine(dir.FullName, name)

    [<Test>]
    let ``Call exifTool and try to parse results`` () =
        let json = callExifTool
                        (location "exifTool.exe")
                        (location @"TestData")

        let tags = Tags.Parse(json)

        test <@ Seq.length tags = 3 @><commit_msg>Use actual TagRetriever in tests<commit_after>﻿namespace Muffin.Pictures.Archiver.Tests

open Swensen.Unquote
open NUnit.Framework
open FSharp.Data

open Muffin.Pictures.Archiver.Tests.TestHelpers
open Muffin.Pictures.Archiver.Domain

module TagTests =
    open System.IO
    open Muffin.Pictures.Archiver.TagRetriever

    let private location name =
        System.Reflection.Assembly.GetExecutingAssembly().Location
        |> Directory.GetParent
        |> fun dir -> Path.Combine(dir.FullName, name)

    [<Test>]
    let ``Call exifTool and try to parse results`` () =
        let tags = callExifTool
                        (location exifFile)
                        (location @"TestData")

        test <@ Seq.length tags = 3 @>
{'fraction_non_alphanumeric': 0.09355765285186705, 'fraction_numerical': 0.0016413623307345096, 'mean_word_length': 2.6551724137931036, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2267459', 'n_tokens_mistral': 727, 'n_tokens_neox': 686, 'n_words': 158}