<commit_before>import json

import keyring

from pyutrack import Credentials
from tests import PyutrackTest


class CredentialsTests(PyutrackTest):
    def test_empty(self):
        c = Credentials('root')
        self.assertIsNone(c.password)
        self.assertIsNone(c.cookies)

    def test_persistence(self):
        c = Credentials('root', 'passwd', {"key": "value"})
        c.persist()
        self.assertEqual(
            keyring.get_password(Credentials.KEYRING_PASSWORD, 'root'), 'passwd'
        )
        self.assertEqual(
            json.loads(keyring.get_password(Credentials.KEYRING_COOKIE, 'root')),
            {"key": "value"}

        )

<commit_msg>Add test for credentials reload<commit_after>import json

import keyring

from pyutrack import Credentials
from tests import PyutrackTest


class CredentialsTests(PyutrackTest):
    def test_empty(self):
        c = Credentials('root')
        self.assertIsNone(c.password)
        self.assertIsNone(c.cookies)

    def test_persistence(self):
        c = Credentials('root', 'passwd', {"key": "value"})
        c.persist()
        self.assertEqual(
            keyring.get_password(Credentials.KEYRING_PASSWORD, 'root'), 'passwd'
        )
        self.assertEqual(
            json.loads(keyring.get_password(Credentials.KEYRING_COOKIE, 'root')),
            {"key": "value"}

        )

    def test_reload(self):
        Credentials('root', 'passwd', {"key": "value"}).persist()
        c = Credentials('root')
        self.assertEqual(
            keyring.get_password(Credentials.KEYRING_PASSWORD, 'root'), 'passwd'
        )
        self.assertEqual(
            json.loads(keyring.get_password(Credentials.KEYRING_COOKIE, 'root')),
            {"key": "value"}

        )

{'fraction_non_alphanumeric': 0.1232876712328767, 'fraction_numerical': 0.0, 'mean_word_length': 2.69831223628692, 'pattern_counts': {'":': 6, '<': 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': '5869050', 'n_tokens_mistral': 552, 'n_tokens_neox': 534, 'n_words': 95}