<commit_before>import hashlib
import sys


class Plugin:
    def on_command(self, bot, msg):
        if len(sys.argv) >= 2:
            algorithm = sys.argv[1]
            contents = " ".join(sys.argv[2:])
            if not contents:
                contents = sys.stdin.read().strip()

            h = hashlib.new(algorithm)
            h.update(bytes(contents, "utf-8"))
            print(h.hexdigest())
        else:
            print(self.on_help())

    def on_help(self):
        return "Usage: hash <algorithm> <contents>"<commit_msg>Add tests for hash plugin<commit_after>import io
import hashlib
import unittest


class Plugin:
    def on_command(self, bot, msg, stdin, stdout, reply):
        if len(msg["args"]) >= 2:
            algorithm = msg["args"][1]
            contents = " ".join(msg["args"][2:])
            if not contents:
                contents = stdin.read().strip()

            try:
                h = hashlib.new(algorithm)
            except ValueError:
                print("No such algorithm:", algorithm, file=stdout)
            except TypeError:
                print(self.on_help(), file=stdout)
            else:
                h.update(bytes(contents, "utf-8"))
                print(h.hexdigest(), file=stdout)
        else:
            print(self.on_help(), file=stdout)

    def on_help(self):
        return "Usage: hash <algorithm> <contents>"


class Test(unittest.TestCase):
    def setUp(self):
        self.plugin = Plugin()

    def test_md5(self):
        stdout = io.StringIO()
        self.plugin.on_command(None, {"args": [None, "md5", "hello"]}, None, stdout, None)
        self.assertEqual("5d41402abc4b2a76b9719d911017c592", stdout.getvalue().strip())

    def test_sha1(self):
        stdout = io.StringIO()
        self.plugin.on_command(None, {"args": [None, "sha1", "hello"]}, None, stdout, None)
        self.assertEqual("aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d", stdout.getvalue().strip())

    def test_sha512(self):
        stdout = io.StringIO()
        self.plugin.on_command(None, {"args": [None, "sha512", "hello"]}, None, stdout, None)
        self.assertEqual("9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043", stdout.getvalue().strip())

    def test_help(self):
        self.assertTrue(self.plugin.on_help())

    def test_no_args(self):
        stdout = io.StringIO()
        self.plugin.on_command(None, {"args": [None]}, stdout, stdout, None)
        self.assertEqual(self.plugin.on_help(), stdout.getvalue().strip())

        stdout = io.StringIO()
        self.plugin.on_command(None, {"args": [None, None]}, stdout, stdout, None)
        self.assertEqual(self.plugin.on_help(), stdout.getvalue().strip())
{'fraction_non_alphanumeric': 0.14053468208092484, 'fraction_numerical': 0.04660404624277457, 'mean_word_length': 2.5545571245186136, 'pattern_counts': {'":': 5, '<': 7, '<?xml version=': 0, '>': 9, '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': '3986943', 'n_tokens_mistral': 976, 'n_tokens_neox': 892, 'n_words': 169}