<commit_before>import { expect, testImg } from "./chai.spec"
import { ExifTool, Tags, WriteTags } from "./ExifTool"

describe("WriteTask", () => {
  const exiftool = new ExifTool(1)
  after(() => exiftool.end())

  async function assertRoundTrip(args: {
    tag: keyof Tags
    inputValue: string | number
    expectedValue?: string
    imgName?: string
    args?: string[]
  }) {
    const src = await testImg(args.imgName)
    const wt: WriteTags = {}
    wt[args.tag] = args.inputValue
    await exiftool.write(src, wt, args.args)
    const result = await exiftool.read(src)
    const expected =
      args.expectedValue == null ? String(args.inputValue) : args.expectedValue
    expect(String(result[args.tag])).to.eql(expected)
    return
  }

  it("round-trips a comment", async () => {
    return assertRoundTrip({
      tag: "XPComment",
      inputValue: "new comment from " + new Date()
    })
  })

  it("round-trips a non-latin comment", async () => {
    return assertRoundTrip({
      tag: "XPComment",
      inputValue: "早安晨之美" + new Date()
    })
  })

  it("round-trips a comment with non-latin filename", async () => {
    return assertRoundTrip({
      tag: "XPComment",
      inputValue: "new comment from " + new Date(),
      imgName: "中文.jpg"
    })
  })

  it("round-trips a non-latin comment with non-latin filename", async () => {
    return assertRoundTrip({
      tag: "XPComment",
      inputValue: "早安晨之美" + new Date(),
      imgName: "中文.jpg"
    })
  })

  it("round-trips a numeric Orientation", async () => {
    return assertRoundTrip({
      tag: "Orientation",
      args: ["-n"],
      inputValue: 8,
      expectedValue: "Rotate 270 CW"
    })
  })

  it("round-trips a string Orientation 90 CW", async () => {
    return assertRoundTrip({
      tag: "Orientation",
      inputValue: "Rotate 90 CW"
    })
  })

  it("round-trips a string Orientation 180 CW", async () => {
    return assertRoundTrip({
      tag: "Orientation",
      inputValue: "Rotate 180"
    })
  })

  it("updates DateTimeOriginal to a specific time", async () => {
    return assertRoundTrip({
      tag: "DateTimeOriginal",
      inputValue: "2017-11-15T12:34:56",
      expectedValue: "2017-11-15T12:34:56.000"
    })
  })

  it("rejects setting to a non-time value", async () => {
    const src = await testImg()
    return expect(
      exiftool.write(src, { DateTimeOriginal: "this is not a time" })
    ).to.be.rejectedWith(/Invalid date\/time/)
  })

  it("rejects a numeric Orientation without -n", async () => {
    const src = await testImg()
    return expect(exiftool.write(src, { Orientation: "3" })).to.be.rejectedWith(
      /Can't convert IFD0:Orientation/
    )
  })

  it("rejects unknown files", () => {
    return expect(
      exiftool.write("/tmp/.nonexistant-" + Date.now(), { XPComment: "boom" })
    ).to.be.rejectedWith(/File not found/)
  })

  it("rejects unknown tags", async () => {
    const src = await testImg()
    return expect(
      exiftool.write(src, { RandomTag: 123 } as any)
    ).to.be.rejectedWith(/Tag \'RandomTag\' is not defined/)
  })
})
<commit_msg>ENOENT because we're stating the file now<commit_after>import { expect, testImg } from "./chai.spec"
import { ExifTool, Tags, WriteTags } from "./ExifTool"

describe("WriteTask", () => {
  const exiftool = new ExifTool(1)
  after(() => exiftool.end())

  async function assertRoundTrip(args: {
    tag: keyof Tags
    inputValue: string | number
    expectedValue?: string
    imgName?: string
    args?: string[]
  }) {
    const src = await testImg(args.imgName)
    const wt: WriteTags = {}
    wt[args.tag] = args.inputValue
    await exiftool.write(src, wt, args.args)
    const result = await exiftool.read(src)
    const expected =
      args.expectedValue == null ? String(args.inputValue) : args.expectedValue
    expect(String(result[args.tag])).to.eql(expected)
    return
  }

  it("round-trips a comment", async () => {
    return assertRoundTrip({
      tag: "XPComment",
      inputValue: "new comment from " + new Date()
    })
  })

  it("round-trips a non-latin comment", async () => {
    return assertRoundTrip({
      tag: "XPComment",
      inputValue: "早安晨之美" + new Date()
    })
  })

  it("round-trips a comment with non-latin filename", async () => {
    return assertRoundTrip({
      tag: "XPComment",
      inputValue: "new comment from " + new Date(),
      imgName: "中文.jpg"
    })
  })

  it("round-trips a non-latin comment with non-latin filename", async () => {
    return assertRoundTrip({
      tag: "XPComment",
      inputValue: "早安晨之美" + new Date(),
      imgName: "中文.jpg"
    })
  })

  it("round-trips a numeric Orientation", async () => {
    return assertRoundTrip({
      tag: "Orientation",
      args: ["-n"],
      inputValue: 8,
      expectedValue: "Rotate 270 CW"
    })
  })

  it("round-trips a string Orientation 90 CW", async () => {
    return assertRoundTrip({
      tag: "Orientation",
      inputValue: "Rotate 90 CW"
    })
  })

  it("round-trips a string Orientation 180 CW", async () => {
    return assertRoundTrip({
      tag: "Orientation",
      inputValue: "Rotate 180"
    })
  })

  it("updates DateTimeOriginal to a specific time", async () => {
    return assertRoundTrip({
      tag: "DateTimeOriginal",
      inputValue: "2017-11-15T12:34:56",
      expectedValue: "2017-11-15T12:34:56.000"
    })
  })

  it("rejects setting to a non-time value", async () => {
    const src = await testImg()
    return expect(
      exiftool.write(src, { DateTimeOriginal: "this is not a time" })
    ).to.be.rejectedWith(/Invalid date\/time/)
  })
  
  it("rejects a numeric Orientation without -n", async () => {
    const src = await testImg()
    return expect(exiftool.write(src, { Orientation: "3" })).to.be.rejectedWith(
      /Can't convert IFD0:Orientation/
    )
  })

  it("rejects unknown files", () => {
    return expect(
      exiftool.write("/tmp/.nonexistant-" + Date.now(), { XPComment: "boom" })
    ).to.be.rejectedWith(/ENOENT/)
  })

  it("rejects unknown tags", async () => {
    const src = await testImg()
    return expect(
      exiftool.write(src, { RandomTag: 123 } as any)
    ).to.be.rejectedWith(/Tag \'RandomTag\' is not defined/)
  })
})

{'fraction_non_alphanumeric': 0.15326713645099296, 'fraction_numerical': 0.016335682254964765, 'mean_word_length': 2.819571865443425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '5071929', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2063, 'n_words': 516}