<commit_before>import pickle

from mwtypes import Timestamp
from nose.tools import eq_

from ....datasources import revision_oriented
from ....dependencies import solve
from ..revision_oriented import MW_REGISTRATION_EPOCH, revision


def test_revision():

    cache = {revision_oriented.revision.timestamp: Timestamp(0)}
    eq_(solve(revision.day_of_week, cache=cache), 3)  # Thursday, Jan 1 1970

    cache = {revision_oriented.revision.timestamp: Timestamp(0)}
    eq_(solve(revision.hour_of_day, cache=cache), 0)  # Midnight

    eq_(pickle.loads(pickle.dumps(revision.day_of_week)), revision.day_of_week)
    eq_(pickle.loads(pickle.dumps(revision.hour_of_day)), revision.hour_of_day)


def test_page_creation():

    cache = {
        revision_oriented.revision.timestamp: Timestamp(10),
        revision_oriented.revision.page.creation.timestamp: Timestamp(0)
    }
    eq_(solve(revision.page.creation.seconds_since, cache=cache), 10)

    eq_(pickle.loads(pickle.dumps(revision.page.creation.seconds_since)),
        revision.page.creation.seconds_since)


def test_user_registration():

    cache = {
        revision_oriented.revision.timestamp: Timestamp(10),
        revision_oriented.revision.user.id: 10,
        revision_oriented.revision.user.info.registration: Timestamp(0)
    }
    eq_(solve(revision.user.seconds_since_registration, cache=cache), 10)

    # Anon (no registration)
    cache = {
        revision_oriented.revision.timestamp: Timestamp(10),
        revision_oriented.revision.user.id: None,
        revision_oriented.revision.user.info.registration: None
    }
    eq_(solve(revision.user.seconds_since_registration, cache=cache), 0)

    # Old user (no registration)
    cache = {
        revision_oriented.revision.timestamp: MW_REGISTRATION_EPOCH + 10,
        revision_oriented.revision.user.id: 10,
        revision_oriented.revision.user.info.registration: None
    }
    eq_(solve(revision.user.seconds_since_registration, cache=cache), 10)

    # Old user (broken registration date)
    cache = {
        revision_oriented.revision.timestamp: Timestamp(0),
        revision_oriented.revision.user.id: 10,
        revision_oriented.revision.user.info.registration: Timestamp(10)
    }<commit_msg>Fixes test for time_since_registration for anons.<commit_after>import pickle

from mwtypes import Timestamp
from nose.tools import eq_

from ....datasources import revision_oriented
from ....dependencies import solve
from ..revision_oriented import MW_REGISTRATION_EPOCH, revision


def test_revision():

    cache = {revision_oriented.revision.timestamp: Timestamp(0)}
    eq_(solve(revision.day_of_week, cache=cache), 3)  # Thursday, Jan 1 1970

    cache = {revision_oriented.revision.timestamp: Timestamp(0)}
    eq_(solve(revision.hour_of_day, cache=cache), 0)  # Midnight

    eq_(pickle.loads(pickle.dumps(revision.day_of_week)), revision.day_of_week)
    eq_(pickle.loads(pickle.dumps(revision.hour_of_day)), revision.hour_of_day)


def test_page_creation():

    cache = {
        revision_oriented.revision.timestamp: Timestamp(10),
        revision_oriented.revision.page.creation.timestamp: Timestamp(0)
    }
    eq_(solve(revision.page.creation.seconds_since, cache=cache), 10)

    eq_(pickle.loads(pickle.dumps(revision.page.creation.seconds_since)),
        revision.page.creation.seconds_since)


def test_user_registration():

    cache = {
        revision_oriented.revision.timestamp: Timestamp(10),
        revision_oriented.revision.user.id: 10,
        revision_oriented.revision.user.info.registration: Timestamp(0)
    }
    eq_(solve(revision.user.seconds_since_registration, cache=cache), 10)

    # Anon (no registration)
    cache = {
        revision_oriented.revision.timestamp: Timestamp(10),
        revision_oriented.revision.user.id: 0,
        revision_oriented.revision.user.info.registration: None
    }
    eq_(solve(revision.user.seconds_since_registration, cache=cache), 0)

    # Old user (no registration)
    cache = {
        revision_oriented.revision.timestamp: MW_REGISTRATION_EPOCH + 10,
        revision_oriented.revision.user.id: 10,
        revision_oriented.revision.user.info.registration: None
    }
    eq_(solve(revision.user.seconds_since_registration, cache=cache), 10)

    # Old user (broken registration date)
    cache = {
        revision_oriented.revision.timestamp: Timestamp(0),
        revision_oriented.revision.user.id: 10,
        revision_oriented.revision.user.info.registration: Timestamp(10)
    }
{'fraction_non_alphanumeric': 0.10525149567914913, 'fraction_numerical': 0.01573232882783071, 'mean_word_length': 3.965896589658966, 'pattern_counts': {'":': 0, '<': 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': '3313612', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1428, 'n_words': 225}