<commit_before>from minqlx_plugin_test import *

from redis import Redis, StrictRedis

import unittest

from mockito import *
from mockito.matchers import *
from hamcrest import *

from frag_stats import *


class FragStatsTests(unittest.TestCase):

    def setUp(self):
        setup_plugin()
        setup_cvars({
            "qlx_fragstats_toplimit": "10"
        })
        setup_game_in_progress()

        self.plugin = frag_stats()
        self.reply_channel = mocked_channel()

        self.plugin.database = Redis
        self.db = mock(StrictRedis)
        self.plugin._db_instance = self.db

        when(self.db).zincrby(any, any, any).thenReturn(None)
        when(self.db).zincrby(any, any, any).thenReturn(None)
        when(self.db).set(any, any).thenReturn(None)

    def tearDown(self):
        unstub()

    def test_handle_player_disconnect_records_player_name(self):
        player = fake_player(123, "Disconnecting Player")

        self.plugin.handle_player_disconnect(player, "quit")

        verify(self.db).set("minqlx:players:{}:last_used_name".format(player.steam_id),
                            player.name)

    def test_handle_game_countdown_clears_frag_log(self):
        self.plugin.frag_log = [(123, 456)]

        self.plugin.handle_game_countdown()

        assert_that(self.plugin.frag_log, is_([]))

    def test_handle_death_records_frag_log_entry(self):
        victim = fake_player(123, "Fragged Player", team="red")
        killer = fake_player(456, "Fragging Player", team="blue")

        connected_players(victim, killer)

        self.plugin.handle_death(victim, killer, {"MOD": "ROCKET"})

        assert_that(self.plugin.frag_log, contains_inanyorder((killer.steam_id, victim.steam_id)))

    def test_handle_death_records_soulz_in_db(self):
        victim = fake_player(123, "Fragged Player", team="red")
        killer = fake_player(456, "Fragging Player", team="blue")

        connected_players(victim, killer)

        self.plugin.handle_death(victim, killer, {"MOD": "ROCKET"})

        verify(self.db).zincrby("minqlx:players:{}:soulz".format(killer.steam_id), 1, victim.steam_id)

    def test_handle_death_records_reaper_in_db(self):
        victim = fake_player(123, "Fragged Player", team="red")
        killer = fake_player(456, "Fragging Player", team="blue")

        connected_players(victim, killer)

        self.plugin.handle_death(victim, killer, {"MOD": "ROCKET"})

        verify(self.db).zincrby("minqlx:players:{}:reaperz".format(victim.steam_id), 1, killer.steam_id)

    def test_handle_death_on_own_death_does_nothing(self):
        victim = fake_player(123, "Fragged Player", team="red")

        connected_players(victim)

        self.plugin.handle_death(victim, victim, {"MOD": "ROCKET"})

        assert_that(self.plugin.frag_log, not_(contains(victim.steam_id)))

    def test_handle_death_in_warmup_does_not_record_frag_log_entry(self):
        setup_game_in_warmup()

        victim = fake_player(123, "Fragged Player", team="red")
        killer = fake_player(456, "Fragging Player", team="blue")

        connected_players(victim, killer)<commit_msg>fixed hamcrest handling for contains deprecation<commit_after>from minqlx_plugin_test import *

from redis import Redis, StrictRedis

import unittest

from mockito import *
from mockito.matchers import *
from hamcrest import *

from frag_stats import *


class FragStatsTests(unittest.TestCase):

    def setUp(self):
        setup_plugin()
        setup_cvars({
            "qlx_fragstats_toplimit": "10"
        })
        setup_game_in_progress()

        self.plugin = frag_stats()
        self.reply_channel = mocked_channel()

        self.plugin.database = Redis
        self.db = mock(StrictRedis)
        self.plugin._db_instance = self.db

        when(self.db).zincrby(any, any, any).thenReturn(None)
        when(self.db).zincrby(any, any, any).thenReturn(None)
        when(self.db).set(any, any).thenReturn(None)

    def tearDown(self):
        unstub()

    def test_handle_player_disconnect_records_player_name(self):
        player = fake_player(123, "Disconnecting Player")

        self.plugin.handle_player_disconnect(player, "quit")

        verify(self.db).set("minqlx:players:{}:last_used_name".format(player.steam_id),
                            player.name)

    def test_handle_game_countdown_clears_frag_log(self):
        self.plugin.frag_log = [(123, 456)]

        self.plugin.handle_game_countdown()

        assert_that(self.plugin.frag_log, is_([]))

    def test_handle_death_records_frag_log_entry(self):
        victim = fake_player(123, "Fragged Player", team="red")
        killer = fake_player(456, "Fragging Player", team="blue")

        connected_players(victim, killer)

        self.plugin.handle_death(victim, killer, {"MOD": "ROCKET"})

        assert_that(self.plugin.frag_log, contains_inanyorder((killer.steam_id, victim.steam_id)))

    def test_handle_death_records_soulz_in_db(self):
        victim = fake_player(123, "Fragged Player", team="red")
        killer = fake_player(456, "Fragging Player", team="blue")

        connected_players(victim, killer)

        self.plugin.handle_death(victim, killer, {"MOD": "ROCKET"})

        verify(self.db).zincrby("minqlx:players:{}:soulz".format(killer.steam_id), 1, victim.steam_id)

    def test_handle_death_records_reaper_in_db(self):
        victim = fake_player(123, "Fragged Player", team="red")
        killer = fake_player(456, "Fragging Player", team="blue")

        connected_players(victim, killer)

        self.plugin.handle_death(victim, killer, {"MOD": "ROCKET"})

        verify(self.db).zincrby("minqlx:players:{}:reaperz".format(victim.steam_id), 1, killer.steam_id)

    def test_handle_death_on_own_death_does_nothing(self):
        victim = fake_player(123, "Fragged Player", team="red")

        connected_players(victim)

        self.plugin.handle_death(victim, victim, {"MOD": "ROCKET"})

        assert_that(self.plugin.frag_log, not_(contains_exactly(victim.steam_id)))

    def test_handle_death_in_warmup_does_not_record_frag_log_entry(self):
        setup_game_in_warmup()

        victim = fake_player(123, "Fragged Player", team="red")
        killer = fake_player(456, "Fragging Player", team="blue")

        connected_players(victim, killer)
{'fraction_non_alphanumeric': 0.12038650403928401, 'fraction_numerical': 0.012672263583082528, 'mean_word_length': 3.568740955137482, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, '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': '6632728', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2074, 'n_words': 328}