<commit_before>import { ExifTool } from './exiftool'
import { expect } from 'chai'
import * as _path from 'path'

const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)

describe('ExifTool', () => {
  const exiftool = new ExifTool(2)
  const truncated = _path.join(__dirname, '..', 'test', 'truncated.jpg')
  const noexif = _path.join(__dirname, '..', 'test', 'noexif.jpg')
  const img = _path.join(__dirname, '..', 'test', 'img.jpg')

  function runningProcs(): number {
    return exiftool['procs']().length
  }

  it('returns the correct version', () => {
    return expect(exiftool.version()).to.become('10.31')
  })

  it('returns expected results for a given file', () => {
    return expect(exiftool.read(img).then(tags => tags.Model)).to.eventually.eql('iPhone 7 Plus')
  })

  it('returns warning for a truncated file', () => {
    return expect(exiftool.read(truncated).then(tags => tags.Warning)).to.eventually.eql('JPEG format error')
  })

  function normalize(tagNames: string[]): string[] {
    return tagNames.filter(i => i !== 'FileInodeChangeDate' && i !== 'FileCreateDate').sort()
  }

  it('returns no exif metadata for an image with no headers', () => {
    return expect(exiftool.read(noexif).then(tags => normalize(Object.keys(tags)))).to.become(normalize([
      'BitsPerSample',
      'ColorComponents',
      'Directory',
      'EncodingProcess',
      'ExifToolVersion',
      'FileAccessDate',
      'FileModifyDate',
      'FileName',
      'FilePermissions',
      'FileSize',
      'FileType',
      'FileTypeExtension',
      'ImageHeight',
      'ImageSize',
      'ImageWidth',
      'Megapixels',
      'MIMEType',
      'SourceFile',
      'YCbCrSubSampling',
      'errors'
    ]))
  })

  it('returns error for missing file', () => {
    return expect(exiftool.read('bogus')).to.eventually.be.rejectedWith(/File not found/)
  })

  it('ends with multiple procs', () => {
    const promises = [exiftool.read(img), exiftool.read(img)]
    expect(runningProcs()).to.eql(2)
    return expect(Promise.all(promises).then(() => exiftool.end()).then(() => runningProcs())).to.become(0)
  })

})
<commit_msg>10.33<commit_after>import { ExifTool } from './exiftool'
import { expect } from 'chai'
import * as _path from 'path'

const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
chai.use(chaiAsPromised)

describe('ExifTool', () => {
  const exiftool = new ExifTool(2)
  const truncated = _path.join(__dirname, '..', 'test', 'truncated.jpg')
  const noexif = _path.join(__dirname, '..', 'test', 'noexif.jpg')
  const img = _path.join(__dirname, '..', 'test', 'img.jpg')

  function runningProcs(): number {
    return exiftool['procs']().length
  }

  it('returns the correct version', () => {
    return expect(exiftool.version()).to.become('10.33')
  })

  it('returns expected results for a given file', () => {
    return expect(exiftool.read(img).then(tags => tags.Model)).to.eventually.eql('iPhone 7 Plus')
  })

  it('returns warning for a truncated file', () => {
    return expect(exiftool.read(truncated).then(tags => tags.Warning)).to.eventually.eql('JPEG format error')
  })

  function normalize(tagNames: string[]): string[] {
    return tagNames.filter(i => i !== 'FileInodeChangeDate' && i !== 'FileCreateDate').sort()
  }

  it('returns no exif metadata for an image with no headers', () => {
    return expect(exiftool.read(noexif).then(tags => normalize(Object.keys(tags)))).to.become(normalize([
      'BitsPerSample',
      'ColorComponents',
      'Directory',
      'EncodingProcess',
      'ExifToolVersion',
      'FileAccessDate',
      'FileModifyDate',
      'FileName',
      'FilePermissions',
      'FileSize',
      'FileType',
      'FileTypeExtension',
      'ImageHeight',
      'ImageSize',
      'ImageWidth',
      'Megapixels',
      'MIMEType',
      'SourceFile',
      'YCbCrSubSampling',
      'errors'
    ]))
  })

  it('returns error for missing file', () => {
    return expect(exiftool.read('bogus')).to.eventually.be.rejectedWith(/File not found/)
  })

  it('ends with multiple procs', () => {
    const promises = [exiftool.read(img), exiftool.read(img)]
    expect(runningProcs()).to.eql(2)
    return expect(Promise.all(promises).then(() => exiftool.end()).then(() => runningProcs())).to.become(0)
  })

})

{'fraction_non_alphanumeric': 0.1797984425103069, 'fraction_numerical': 0.004580852038479157, 'mean_word_length': 3.6457446808510636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '7208432', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1448, 'n_words': 278}