<commit_before>
from dash.fingerprint import build_fingerprint, check_fingerprint

version = 1
hash_value = 1

valid_resources = [
    {'path': 'react@16.8.6.min.js', 'fingerprint': 'react@16.v1m1.8.6.min.js'},
    {'path': 'react@16.8.6.min.js', 'fingerprint': 'react@16.v1_1_1m1234567890abcdef.8.6.min.js', 'version': '1.1.1', 'hash': '1234567890abcdef' },
    {'path': 'react@16.8.6.min.js', 'fingerprint': 'react@16.v1_1_1-alpha_1m1234567890abcdef.8.6.min.js', 'version': '1.1.1-alpha.1', 'hash': '1234567890abcdef' },
    {'path': 'dash.plotly.js', 'fingerprint': 'dash.v1m1.plotly.js'},
    {'path': 'dash.plotly.j_s', 'fingerprint': 'dash.v1m1.plotly.j_s'},
    {'path': 'dash.plotly.css', 'fingerprint': 'dash.v1m1.plotly.css'},
    {'path': 'dash.plotly.xxx.yyy.zzz', 'fingerprint': 'dash.v1m1.plotly.xxx.yyy.zzz'},
    {'path': 'dash~plotly.js', 'fingerprint': 'dash~plotly.v1m1.js'}
]

valid_fingerprints = [
    'react@16.v1_1_2m1571771240.8.6.min.js',
    'dash.plotly.v1_1_1m1234567890.js',
    'dash.plotly.v1_1_1m1234567890.j_s',
    'dash.plotly.v1_1_1m1234567890.css',
    'dash.plotly.v1_1_1m1234567890.xxx.yyy.zzz',
    'dash.plotly.v1_1_1-alpha1m1234567890.js',
    'dash.plotly.v1_1_1-alpha_3m1234567890.js',
    'dash.plotly.v1_1_1m1234567890123.js',
    'dash.plotly.v1_1_1m4bc3.js',
    'dash~plotly.v1m1.js'
]

invalid_fingerprints = [
    'dash.plotly.v1_1_1m1234567890..js',
    'dash.plotly.v1_1_1m1234567890.',
    'dash.plotly.v1_1_1m1234567890..',
    'dash.plotly.v1_1_1m1234567890.js.',
    'dash.plotly.v1_1_1m1234567890.j-s'
]

def test_fingerprint():
    for resource in valid_resources:
        # The fingerprint matches expectations
        fingerprint = build_fingerprint(resource.get('path'), resource.get('version', version), resource.get('hash', hash_value))
        assert fingerprint == resource.get('fingerprint')

        (original_path, has_fingerprint) = check_fingerprint(fingerprint)
        # The inverse operation returns that the fingerprint was valid and the original path
        assert has_fingerprint
        assert original_path == resource.get('path')

    for resource in valid_fingerprints:
        (_, has_fingerprint) = check_fingerprint(resource)
        assert has_fingerprint

    for resource in invalid_fingerprints:
        (_, has_fingerprint) = check_fingerprint(resource)
        assert not has_fingerprint<commit_msg>lint test_fingerprint<commit_after>from dash.fingerprint import build_fingerprint, check_fingerprint

version = 1
hash_value = 1

valid_resources = [
    {"path": "react@16.8.6.min.js", "fingerprint": "react@16.v1m1.8.6.min.js"},
    {
        "path": "react@16.8.6.min.js",
        "fingerprint": "react@16.v1_1_1m1234567890abcdef.8.6.min.js",
        "version": "1.1.1",
        "hash": "1234567890abcdef",
    },
    {
        "path": "react@16.8.6.min.js",
        "fingerprint": "react@16.v1_1_1-alpha_1m1234567890abcdef.8.6.min.js",
        "version": "1.1.1-alpha.1",
        "hash": "1234567890abcdef",
    },
    {"path": "dash.plotly.js", "fingerprint": "dash.v1m1.plotly.js"},
    {"path": "dash.plotly.j_s", "fingerprint": "dash.v1m1.plotly.j_s"},
    {"path": "dash.plotly.css", "fingerprint": "dash.v1m1.plotly.css"},
    {"path": "dash.plotly.xxx.yyy.zzz", "fingerprint": "dash.v1m1.plotly.xxx.yyy.zzz"},
    {"path": "dash~plotly.js", "fingerprint": "dash~plotly.v1m1.js"},
]

valid_fingerprints = [
    "react@16.v1_1_2m1571771240.8.6.min.js",
    "dash.plotly.v1_1_1m1234567890.js",
    "dash.plotly.v1_1_1m1234567890.j_s",
    "dash.plotly.v1_1_1m1234567890.css",
    "dash.plotly.v1_1_1m1234567890.xxx.yyy.zzz",
    "dash.plotly.v1_1_1-alpha1m1234567890.js",
    "dash.plotly.v1_1_1-alpha_3m1234567890.js",
    "dash.plotly.v1_1_1m1234567890123.js",
    "dash.plotly.v1_1_1m4bc3.js",
    "dash~plotly.v1m1.js",
]

invalid_fingerprints = [
    "dash.plotly.v1_1_1m1234567890..js",
    "dash.plotly.v1_1_1m1234567890.",
    "dash.plotly.v1_1_1m1234567890..",
    "dash.plotly.v1_1_1m1234567890.js.",
    "dash.plotly.v1_1_1m1234567890.j-s",
]


def test_fingerprint():
    for resource in valid_resources:
        # The fingerprint matches expectations
        fingerprint = build_fingerprint(
            resource.get("path"),
            resource.get("version", version),
            resource.get("hash", hash_value),
        )
        assert fingerprint == resource.get("fingerprint")

        (original_path, has_fingerprint) = check_fingerprint(fingerprint)
        # The inverse operation returns that the fingerprint was valid
        # and the original path
        assert has_fingerprint
        assert original_path == resource.get("path")

    for resource in valid_fingerprints:
        (_, has_fingerprint) = check_fingerprint(resource)
        assert has_fingerprint

    for resource in invalid_fingerprints:
        (_, has_fingerprint) = check_fingerprint(resource)
        assert not has_fingerprint
{'fraction_non_alphanumeric': 0.15611043442955744, 'fraction_numerical': 0.11246447421843281, 'mean_word_length': 3.617619493908154, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, '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': '5192550', 'n_tokens_mistral': 2250, 'n_tokens_neox': 1919, 'n_words': 250}