<commit_before>//
//  KeychainTests.swift
//  ELKeychain
//
//  Created by <NAME> on 5/31/16.
//  Copyright © 2016 Walmart. All rights reserved.
//

import XCTest
import ELKeychain

private let testServiceName = "ELKeychainTests-test-service"

class KeychainTests: XCTestCase {
    override func setUp() {
        deleteAllItems(service: testServiceName)
    }
    
    func deleteAllItems(service service: String) {
        let query = [
            kSecClass as String : kSecClassGenericPassword,
            kSecAttrService as String : service]
        
        let _ = try? Keychain.delete(matching: query)
    }
    
    func test_setString_doesNotThrowErrors() {
        let value = "value"
        let account = "test_setString_doesNotThrowErrors"
        
        do {
            try Keychain.set(value, account: account, service: testServiceName)
        } catch let error {
            XCTFail("Unexpected error. \(error)")
        }
        
        // cleanup
        try! Keychain.delete(account: account, service: testServiceName)
    }
    
    func test_getString_returnsKeychainItemForValidQuery() {
        let value = "value"
        let account = "test_getString_returnsKeychainItemForValidQuery"
        var result: String?
        
        try! Keychain.set(value, account: account, service: testServiceName)

        do {
            result = try Keychain.get(account: account, service: testServiceName)
        } catch let error {
            XCTFail("Unexpected error. \(error)")
        }
        
        XCTAssertNotNil(result)
        XCTAssertEqual(result!, value)
        
        try! Keychain.delete(account: account, service: testServiceName)
    }
    
    func test_getData_returnsNilWhenKeychainItemIsNotFound() {
        let account = "test_getData_returnsNilWhenKeychainItemIsNotFound-account"
        
        do {
            let result: NSData? = try Keychain.get(account: account, service: testServiceName)
            XCTAssertNil(result)
        } catch {
            XCTFail("Unexpected error. \(error)")
        }
    }
    
    func test_getData_returnsNilAfterItemIsDeleted() {
        let value = "test_getData_returnsNilAfterItemIsDeleted-value"
        let account = "test_getData_returnsNilAfterItemIsDeleted-account"
       
        do {
            try Keychain.set(value, account: account, service: testServiceName)
            try Keychain.delete(account: account, service: testServiceName)
            
            let data: NSData? = try Keychain.get(account: account, service: testServiceName)

            XCTAssertNil(data)
        } catch let error {
            XCTFail("Unexpected error. \(error)")

        }
    }
    
    func test_delete_doesNotThrowErrorWhenDeletingKeychainItem() {
        let value = "test_delete_doesNotThrowErrorWhenDeletingKeychainItem-value"
        let account = "test_delete_doesNotThrowErrorWhenDeletingKeychainItem-account"
        let service = "test_delete_doesNotThrowErrorWhenDeletingKeychainItem-service"
        let keychain = Keychain(service: service)
        deleteAllItems(service: service)
        
        do {
            try keychain.set(value, account: account)
        } catch let error {
            XCTFail("set call should not fail. Unexpected error. \(error)")
        }
        
        do {
            try keychain.delete(account: account)
        } catch let error {
            XCTFail("delete call should not fail. Unexpected error. \(error)")
        }
        
        deleteAllItems(service: service)
    }
    
    func test_delete_throwsErrorWhenUnableToDeleteItem() {
        let account = "test_delete_throwsErrorWhenUnableToDeleteItem-account"
        
        do {
            try Keychain.delete(account: account, service: testServiceName)
            XCTFail("Expected delete call to throw error")
        } catch _ {
            
        }
    }
}
<commit_msg>remove cleanup code in unit test<commit_after>//
//  KeychainTests.swift
//  ELKeychain
//
//  Created by <NAME> on 5/31/16.
//  Copyright © 2016 Walmart. All rights reserved.
//

import XCTest
import ELKeychain

private let testServiceName = "ELKeychainTests-test-service"

class KeychainTests: XCTestCase {
    override func setUp() {
        deleteAllItems(service: testServiceName)
    }
    
    func deleteAllItems(service service: String) {
        let query = [
            kSecClass as String : kSecClassGenericPassword,
            kSecAttrService as String : service]
        
        let _ = try? Keychain.delete(matching: query)
    }
    
    func test_setString_doesNotThrowErrors() {
        let value = "value"
        let account = "test_setString_doesNotThrowErrors"
        
        do {
            try Keychain.set(value, account: account, service: testServiceName)
        } catch let error {
            XCTFail("Unexpected error. \(error)")
        }
        
        // cleanup
        try! Keychain.delete(account: account, service: testServiceName)
    }
    
    func test_getString_returnsKeychainItemForValidQuery() {
        let value = "value"
        let account = "test_getString_returnsKeychainItemForValidQuery"
        var result: String?
        
        try! Keychain.set(value, account: account, service: testServiceName)

        do {
            result = try Keychain.get(account: account, service: testServiceName)
        } catch let error {
            XCTFail("Unexpected error. \(error)")
        }
        
        XCTAssertNotNil(result)
        XCTAssertEqual(result!, value)
        
        try! Keychain.delete(account: account, service: testServiceName)
    }
    
    func test_getData_returnsNilWhenKeychainItemIsNotFound() {
        let account = "test_getData_returnsNilWhenKeychainItemIsNotFound-account"
        
        do {
            let result: NSData? = try Keychain.get(account: account, service: testServiceName)
            XCTAssertNil(result)
        } catch {
            XCTFail("Unexpected error. \(error)")
        }
    }
    
    func test_getData_returnsNilAfterItemIsDeleted() {
        let value = "test_getData_returnsNilAfterItemIsDeleted-value"
        let account = "test_getData_returnsNilAfterItemIsDeleted-account"
       
        do {
            try Keychain.set(value, account: account, service: testServiceName)
            try Keychain.delete(account: account, service: testServiceName)
            
            let data: NSData? = try Keychain.get(account: account, service: testServiceName)

            XCTAssertNil(data)
        } catch let error {
            XCTFail("Unexpected error. \(error)")

        }
    }
    
    func test_delete_doesNotThrowErrorWhenDeletingKeychainItem() {
        let value = "test_delete_doesNotThrowErrorWhenDeletingKeychainItem-value"
        let account = "test_delete_doesNotThrowErrorWhenDeletingKeychainItem-account"
        let service = "test_delete_doesNotThrowErrorWhenDeletingKeychainItem-service"
        let keychain = Keychain(service: service)
        
        do {
            try keychain.set(value, account: account)
        } catch let error {
            XCTFail("set call should not fail. Unexpected error. \(error)")
        }
        
        do {
            try keychain.delete(account: account)
        } catch let error {
            XCTFail("delete call should not fail. Unexpected error. \(error)")
        }
    }
    
    func test_delete_throwsErrorWhenUnableToDeleteItem() {
        let account = "test_delete_throwsErrorWhenUnableToDeleteItem-account"
        
        do {
            try Keychain.delete(account: account, service: testServiceName)
            XCTFail("Expected delete call to throw error")
        } catch _ {
            
        }
    }
}

{'fraction_non_alphanumeric': 0.07953367875647668, 'fraction_numerical': 0.00233160621761658, 'mean_word_length': 2.2157434402332363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '504943', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2113, 'n_words': 473}