<commit_before>import os

import pytest

import six

import bcrypt


def test_gensalt_basic(monkeypatch):
    monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")
    assert bcrypt.gensalt() == b"$2b$12$KB.uKB.uKB.uKB.uKB.uK."


@pytest.mark.parametrize(("rounds", "expected"), [
    (4, b"$2b$04$KB.uKB.uKB.uKB.uKB.uK."),
    (5, b"$2b$05$KB.uKB.uKB.uKB.uKB.uK."),
    (6, b"$2b$06$KB.uKB.uKB.uKB.uKB.uK."),
    (7, b"$2b$07$KB.uKB.uKB.uKB.uKB.uK."),
    (8, b"$2b$08$KB.uKB.uKB.uKB.uKB.uK."),
    (9, b"$2b$09$KB.uKB.uKB.uKB.uKB.uK."),
    (10, b"$2b$10$KB.uKB.uKB.uKB.uKB.uK."),
    (11, b"$2b$11$KB.uKB.uKB.uKB.uKB.uK."),
    (12, b"$2b$12$KB.uKB.uKB.uKB.uKB.uK."),
    (13, b"$2b$13$KB.uKB.uKB.uKB.uKB.uK."),
    (14, b"$2b$14$KB.uKB.uKB.uKB.uKB.uK."),
    (15, b"$2b$15$KB.uKB.uKB.uKB.uKB.uK."),
    (16, b"$2b$16$KB.uKB.uKB.uKB.uKB.uK."),
    (17, b"$2b$17$KB.uKB.uKB.uKB.uKB.uK."),
    (18, b"$2b$18$KB.uKB.uKB.uKB.uKB.uK."),
    (19, b"$2b$19$KB.uKB.uKB.uKB.uKB.uK."),
    (20, b"$2b$20$KB.uKB.uKB.uKB.uKB.uK."),
    (21, b"$2b$21$KB.uKB.uKB.uKB.uKB.uK."),
    (22, b"$2b$22$KB.uKB.uKB.uKB.uKB.uK."),
    (23, b"$2b$23$KB.uKB.uKB.uKB.uKB.uK."),
    (24, b"$2b$24$KB.uKB.uKB.uKB.uKB.uK."),
])
def test_gensalt_rounds_valid(rounds, expected, monkeypatch):
    monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")
    assert bcrypt.gensalt(rounds) == expected


@pytest.mark.parametrize("rounds", list(range(1, 4)))
def test_gensalt_rounds_invalid(rounds, monkeypatch):
    monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")

    with pytest.raises(ValueError):
        bcrypt.gensalt(rounds)


@pytest.mark.parametrize(("password", "salt", "expected"), [
    (
        b"Kk<PASSWORD>",
        b"$2b$04$cVWp4XaNU8a4v1uMRum2SO",
        b"$2b$04$cVWp4XaNU8a4v1uMRum2SO026BWLIoQMD/TXg5uZV.0P.uO8m3YEm",
    ),
    (
        b"9IeRXmnGxMYbs",
        b"$2b$04$pQ7gRO7e6wx/936oXhNjrO",
        b"$2b$04$pQ7gRO7e6wx/936oXhNjrOUNOHL1D0h1N2IDbJZYs.1ppzSof6SPy",
    ),<commit_msg>Add tests for gensalt(prefix) functionality<commit_after>import os

import pytest

import six

import bcrypt


def test_gensalt_basic(monkeypatch):
    monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")
    assert bcrypt.gensalt() == b"$2b$12$KB.uKB.uKB.uKB.uKB.uK."


@pytest.mark.parametrize(("rounds", "expected"), [
    (4, b"$2b$04$KB.uKB.uKB.uKB.uKB.uK."),
    (5, b"$2b$05$KB.uKB.uKB.uKB.uKB.uK."),
    (6, b"$2b$06$KB.uKB.uKB.uKB.uKB.uK."),
    (7, b"$2b$07$KB.uKB.uKB.uKB.uKB.uK."),
    (8, b"$2b$08$KB.uKB.uKB.uKB.uKB.uK."),
    (9, b"$2b$09$KB.uKB.uKB.uKB.uKB.uK."),
    (10, b"$2b$10$KB.uKB.uKB.uKB.uKB.uK."),
    (11, b"$2b$11$KB.uKB.uKB.uKB.uKB.uK."),
    (12, b"$2b$12$KB.uKB.uKB.uKB.uKB.uK."),
    (13, b"$2b$13$KB.uKB.uKB.uKB.uKB.uK."),
    (14, b"$2b$14$KB.uKB.uKB.uKB.uKB.uK."),
    (15, b"$2b$15$KB.uKB.uKB.uKB.uKB.uK."),
    (16, b"$2b$16$KB.uKB.uKB.uKB.uKB.uK."),
    (17, b"$2b$17$KB.uKB.uKB.uKB.uKB.uK."),
    (18, b"$2b$18$KB.uKB.uKB.uKB.uKB.uK."),
    (19, b"$2b$19$KB.uKB.uKB.uKB.uKB.uK."),
    (20, b"$2b$20$KB.uKB.uKB.uKB.uKB.uK."),
    (21, b"$2b$21$KB.uKB.uKB.uKB.uKB.uK."),
    (22, b"$2b$22$KB.uKB.uKB.uKB.uKB.uK."),
    (23, b"$2b$23$KB.uKB.uKB.uKB.uKB.uK."),
    (24, b"$2b$24$KB.uKB.uKB.uKB.uKB.uK."),
])
def test_gensalt_rounds_valid(rounds, expected, monkeypatch):
    monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")
    assert bcrypt.gensalt(rounds) == expected


@pytest.mark.parametrize("rounds", list(range(1, 4)))
def test_gensalt_rounds_invalid(rounds, monkeypatch):
    monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")

    with pytest.raises(ValueError):
        bcrypt.gensalt(rounds)


def test_gensalt_bad_prefix():
    with pytest.raises(ValueError):
        bcrypt.gensalt(prefix="bad")


def test_gensalt_2a_prefix(monkeypatch):
    monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")
    assert bcrypt.gensalt(prefix=b"2a") == b"$2a$12$KB.uKB.uKB.uKB.uKB.uK."


@pytest.mark.parametrize(("password", "salt", "expected"), [
    (
        b"Kk4DQuMMfZL9o",
        b"$2b$04$cVWp4XaNU8a4v1uMRum2SO",
        b"$2b$04$cVWp4XaNU8a4v1uMRum2SO026BWLIoQMD/TXg5uZV.0P.uO8m3YEm",
    ),
    (
        b"9IeRXmnGxMYbs",
        b"$2b$04$pQ7gRO7e6wx/936oXhNjrO",
        b"$2b$04$pQ7gRO7e6wx/936oXhNjrOUNOHL1D0h1N2IDbJZYs.1ppzSof6SPy",
    ),
{'fraction_non_alphanumeric': 0.22825091575091574, 'fraction_numerical': 0.09684065934065934, 'mean_word_length': 3.594111461619348, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 7, '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': '2445481', 'n_tokens_mistral': 2866, 'n_tokens_neox': 2401, 'n_words': 213}