<commit_before>//
//  DiskFetcherTests.swift
//  Haneke
//
//  Created by <NAME> on 21/09/14.
//  Copyright (c) 2014 Haneke. All rights reserved.
//

import UIKit
import XCTest

class DiskFetcherTests: DiskTestCase {
    
    var sut : DiskFetcher<UIImage>!

    override func setUp() {
        super.setUp()
        directoryPath = directoryPath.stringByAppendingPathComponent(self.name)
        sut = DiskFetcher(path: directoryPath)
    }
    
    func testInit() {
        XCTAssertEqual(sut.path, directoryPath)
    }
    
    func testKey() {
        XCTAssertEqual(sut.key, directoryPath)
    }
    
    func testFetchImage_Success() {
        let image = UIImage.imageWithColor(UIColor.greenColor(), CGSizeMake(10, 20))
        let data = UIImagePNGRepresentation(image)
        data.writeToFile(directoryPath, atomically: true)
        
        let expectation = self.expectationWithDescription(self.name)
        
        sut.fetch(failure: { _ in
            XCTFail("Expected to succeed")
            expectation.fulfill()
        }) {
            let result = $0 as UIImage
            XCTAssertTrue(result.isEqualPixelByPixel(image))
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
    }
    
    func testFetchImage_Failure_NSFileReadNoSuchFileError() {
        let expectation = self.expectationWithDescription(self.name)
        
        sut.fetch(failure: {
            XCTAssertEqual($0!.code, NSFileReadNoSuchFileError)
            XCTAssertNotNil($0!.localizedDescription)
            expectation.fulfill()
        }) { _ in
            XCTFail("Expected to fail")
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
    }
    
    func testFetchImage_Failure_HNKDiskEntityInvalidDataError() {
        let data = NSData.data()
        data.writeToFile(directoryPath, atomically: true)
        
        let expectation = self.expectationWithDescription(self.name)
        
        sut.fetch(failure: {
            XCTAssertEqual($0!.domain, Haneke.Domain)
            XCTAssertEqual($0!.code, Haneke.DiskFetcher.ErrorCode.InvalidData.toRaw())
            XCTAssertNotNil($0!.localizedDescription)
            expectation.fulfill()
        }) { _ in
            XCTFail("Expected to fail")
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
    }

    func testCancelFetch() {
        let image = UIImage.imageWithColor(UIColor.greenColor(), CGSizeMake(10, 20))
        let data = UIImagePNGRepresentation(image)
        data.writeToFile(directoryPath, atomically: true)
        sut.fetch(failure: { _ in
            XCTFail("Unexpected failure")
        }) { _ in
            XCTFail("Unexpected success")
        }
        
        sut.cancelFetch()
        
        self.waitFor(0.1)
    }
    
    func testCancelFetch_NoFetch() {
        sut.cancelFetch()
    }
    
    // MARK: Cache extension
    
    func testCacheFetch_Success() {
        let data = NSData.dataWithLength(1)
        let path = self.writeData(data)
        let expectation = self.expectationWithDescription(self.name)
        let cache = Cache<NSData>(self.name)
        
        cache.fetch(path: path, failure: {_ in
            XCTFail("expected success")
            expectation.fulfill()
        }) {
            XCTAssertEqual($0, data)
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
        
        cache.removeAllValues()
    }
    
    func testCacheFetch_Failure() {
        let path = self.directoryPath.stringByAppendingPathComponent(self.name)
        let expectation = self.expectationWithDescription(self.name)
        let cache = Cache<NSData>(self.name)
        
        cache.fetch(path: path, failure: {_ in
            expectation.fulfill()
        }) { _ in
            XCTFail("expected success")
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
        
        cache.removeAllValues()
    }
    
    func testCacheFetch_WithFormat() {
        let data = NSData.dataWithLength(1)
        let path = self.writeData(data)
        let expectation = self.expectationWithDescription(self.name)
        let cache = Cache<NSData>(self.name)
        let format = Format<NSData>(self.name)
        cache.addFormat(format)
        
        cache.fetch(path: path, formatName: format.name, failure: {_ in
            expectation.fulfill()
        }) { _ in
            XCTFail("expected success")
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
        
        cache.removeAllValues()
    }
}<commit_msg>Fix DiskFetcher tests<commit_after>//
//  DiskFetcherTests.swift
//  Haneke
//
//  Created by <NAME> on 21/09/14.
//  Copyright (c) 2014 Haneke. All rights reserved.
//

import UIKit
import XCTest

class DiskFetcherTests: DiskTestCase {
    
    var sut : DiskFetcher<UIImage>!
    var path : String!

    override func setUp() {
        super.setUp()
        path = self.uniquePath()
        sut = DiskFetcher(path: path)
    }
    
    func testInit() {
        XCTAssertEqual(sut.path, path)
    }
    
    func testKey() {
        XCTAssertEqual(sut.key, path)
    }
    
    func testFetchImage_Success() {
        let image = UIImage.imageWithColor(UIColor.greenColor(), CGSizeMake(10, 20))
        let data = UIImagePNGRepresentation(image)
        data.writeToFile(sut.path, atomically: true)
        
        let expectation = self.expectationWithDescription(self.name)
        
        sut.fetch(failure: { _ in
            XCTFail("Expected to succeed")
            expectation.fulfill()
        }) {
            let result = $0 as UIImage
            XCTAssertTrue(result.isEqualPixelByPixel(image))
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
    }
    
    func testFetchImage_Failure_NSFileReadNoSuchFileError() {
        let expectation = self.expectationWithDescription(self.name)
        
        sut.fetch(failure: {
            XCTAssertEqual($0!.code, NSFileReadNoSuchFileError)
            XCTAssertNotNil($0!.localizedDescription)
            expectation.fulfill()
        }) { _ in
            XCTFail("Expected to fail")
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
    }
    
    func testFetchImage_Failure_HNKDiskEntityInvalidDataError() {
        let data = NSData.data()
        data.writeToFile(sut.path, atomically: true)
        
        let expectation = self.expectationWithDescription(self.name)
        
        sut.fetch(failure: {
            XCTAssertEqual($0!.domain, Haneke.Domain)
            XCTAssertEqual($0!.code, Haneke.DiskFetcher.ErrorCode.InvalidData.toRaw())
            XCTAssertNotNil($0!.localizedDescription)
            expectation.fulfill()
        }) { _ in
            XCTFail("Expected to fail")
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
    }

    func testCancelFetch() {
        let image = UIImage.imageWithColor(UIColor.greenColor(), CGSizeMake(10, 20))
        let data = UIImagePNGRepresentation(image)
        data.writeToFile(directoryPath, atomically: true)
        sut.fetch(failure: { _ in
            XCTFail("Unexpected failure")
        }) { _ in
            XCTFail("Unexpected success")
        }
        
        sut.cancelFetch()
        
        self.waitFor(0.1)
    }
    
    func testCancelFetch_NoFetch() {
        sut.cancelFetch()
    }
    
    // MARK: Cache extension
    
    func testCacheFetch_Success() {
        let data = NSData.dataWithLength(1)
        let path = self.writeData(data)
        let expectation = self.expectationWithDescription(self.name)
        let cache = Cache<NSData>(self.name)
        
        cache.fetch(path: path, failure: {_ in
            XCTFail("expected success")
            expectation.fulfill()
        }) {
            XCTAssertEqual($0, data)
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
        
        cache.removeAllValues()
    }
    
    func testCacheFetch_Failure() {
        let path = self.directoryPath.stringByAppendingPathComponent(self.name)
        let expectation = self.expectationWithDescription(self.name)
        let cache = Cache<NSData>(self.name)
        
        cache.fetch(path: path, failure: {_ in
            expectation.fulfill()
        }) { _ in
            XCTFail("expected success")
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
        
        cache.removeAllValues()
    }
    
    func testCacheFetch_WithFormat() {
        let data = NSData.dataWithLength(1)
        let path = self.writeData(data)
        let expectation = self.expectationWithDescription(self.name)
        let cache = Cache<NSData>(self.name)
        let format = Format<NSData>(self.name)
        cache.addFormat(format)
        
        cache.fetch(path: path, formatName: format.name, failure: {_ in
            XCTFail("expected success")
            expectation.fulfill()
        }) {
            XCTAssertEqual($0, data)
            expectation.fulfill()
        }
        
        self.waitForExpectationsWithTimeout(1, handler: nil)
        
        cache.removeAllValues()
    }
}
{'fraction_non_alphanumeric': 0.09567031820552947, 'fraction_numerical': 0.007407407407407408, 'mean_word_length': 2.0012523481527866, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3726288', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2753, 'n_words': 468}