<commit_before>from collections import Hashable
from datetime import datetime

from sunpy.database.tables import FitsHeaderEntry, Tag, DatabaseEntry,\
    entries_from_query_result
from sunpy.net.vso import VSOClient
import sunpy

import pytest


@pytest.fixture
def query_result():
    client = VSOClient()
    return client.query_legacy('2001/1/1', '2001/1/2', instrument='EIT')


def test_fits_header_entry_equality():
    assert FitsHeaderEntry('key', 'value') == FitsHeaderEntry('key', 'value')
    assert not (FitsHeaderEntry('key', 'value') == FitsHeaderEntry('k', 'v'))


def test_fits_header_entry_inequality():
    assert FitsHeaderEntry('key', 'value') != FitsHeaderEntry('k', 'v')
    assert not (FitsHeaderEntry('k', 'v') != FitsHeaderEntry('k', 'v'))


def test_fits_header_entry_hashability():
    assert not isinstance(FitsHeaderEntry('key', 'value'), Hashable)


def test_tag_equality():
    assert Tag('abc') == Tag('abc')
    assert not (Tag('abc') == Tag('xyz'))


def test_tag_inequality():
    assert Tag('abc') != Tag('xyz')
    assert not (Tag('abc') != Tag('abc'))


def test_tag_hashability():
    assert not isinstance(Tag(''), Hashable)


@pytest.mark.slow
def test_entry_from_qr_block(query_result):
    entry = DatabaseEntry.from_query_result_block(query_result[0])
    expected_entry = DatabaseEntry(
        source='SOHO', provider='SDAC', physobs='intensity',
        fileid='/archive/soho/private/data/processed/eit/lz/2001/01/efz20010101.010014',
        observation_time_start=datetime(2001, 1, 1, 1, 0, 14),
        observation_time_end=datetime(2001, 1, 1, 1, 0, 21),
        instrument='EIT', size=2059.0, waveunit='Angstrom', wavemin=171.0,
        wavemax=171.0)
    assert entry == expected_entry


def test_add_fits_header_entries_from_file():
    entry = DatabaseEntry()
    assert entry.fits_header_entries == []
    entry.add_fits_header_entries_from_file(sunpy.RHESSI_EVENT_LIST)
    assert entry.fits_header_entries == [
        FitsHeaderEntry('SIMPLE', True),
        FitsHeaderEntry('BITPIX', 8),
        FitsHeaderEntry('NAXIS', 0),
        FitsHeaderEntry('EXTEND', True),
        FitsHeaderEntry('DATE', '2011-09-13T15:37:38'),
        FitsHeaderEntry('ORIGIN', 'RHESSI'),
        FitsHeaderEntry('OBSERVER', 'Unknown'),
        FitsHeaderEntry('TELESCOP', 'RHESSI'),
        FitsHeaderEntry('INSTRUME', 'RHESSI'),
        FitsHeaderEntry('OBJECT', 'Sun'),
        FitsHeaderEntry('DATE_OBS', '2002-02-20T11:06:00.000'),
        FitsHeaderEntry('DATE_END', '2002-02-20T11:06:43.330'),
        FitsHeaderEntry('TIME_UNI', 1),
        FitsHeaderEntry('ENERGY_L', 25.0),
        FitsHeaderEntry('ENERGY_H', 40.0),
        FitsHeaderEntry('TIMESYS', '1979-01-01T00:00:00'),
        FitsHeaderEntry('TIMEUNIT', 'd')]


@pytest.mark.slow
def test_entries_from_query_result(query_result):
    entries = list(entries_from_query_result(query_result))
    assert len(entries) == 122
    snd_entry = entries[1]
    expected_entry = DatabaseEntry(
        source='SOHO', provider='SDAC', physobs='intensity',
        fileid='/archive/soho/private/data/processed/eit/lz/2001/01/efz20010101.070014',
        observation_time_start=datetime(2001, 1, 1, 7, 0, 14),
        observation_time_end=datetime(2001, 1, 1, 7, 0, 21),
        instrument='EIT', size=2059.0, waveunit='Angstrom', wavemin=171.0,
        wavemax=171.0)
    assert snd_entry == expected_entry
<commit_msg>update the test to the latest change (making Tag objects hashable)<commit_after>from collections import Hashable
from datetime import datetime

from sunpy.database.tables import FitsHeaderEntry, Tag, DatabaseEntry,\
    entries_from_query_result
from sunpy.net.vso import VSOClient
import sunpy

import pytest


@pytest.fixture
def query_result():
    client = VSOClient()
    return client.query_legacy('2001/1/1', '2001/1/2', instrument='EIT')


def test_fits_header_entry_equality():
    assert FitsHeaderEntry('key', 'value') == FitsHeaderEntry('key', 'value')
    assert not (FitsHeaderEntry('key', 'value') == FitsHeaderEntry('k', 'v'))


def test_fits_header_entry_inequality():
    assert FitsHeaderEntry('key', 'value') != FitsHeaderEntry('k', 'v')
    assert not (FitsHeaderEntry('k', 'v') != FitsHeaderEntry('k', 'v'))


def test_fits_header_entry_hashability():
    assert not isinstance(FitsHeaderEntry('key', 'value'), Hashable)


def test_tag_equality():
    assert Tag('abc') == Tag('abc')
    assert not (Tag('abc') == Tag('xyz'))


def test_tag_inequality():
    assert Tag('abc') != Tag('xyz')
    assert not (Tag('abc') != Tag('abc'))


def test_tag_hashability():
    assert isinstance(Tag(''), Hashable)


@pytest.mark.slow
def test_entry_from_qr_block(query_result):
    entry = DatabaseEntry.from_query_result_block(query_result[0])
    expected_entry = DatabaseEntry(
        source='SOHO', provider='SDAC', physobs='intensity',
        fileid='/archive/soho/private/data/processed/eit/lz/2001/01/efz20010101.010014',
        observation_time_start=datetime(2001, 1, 1, 1, 0, 14),
        observation_time_end=datetime(2001, 1, 1, 1, 0, 21),
        instrument='EIT', size=2059.0, waveunit='Angstrom', wavemin=171.0,
        wavemax=171.0)
    assert entry == expected_entry


def test_add_fits_header_entries_from_file():
    entry = DatabaseEntry()
    assert entry.fits_header_entries == []
    entry.add_fits_header_entries_from_file(sunpy.RHESSI_EVENT_LIST)
    assert entry.fits_header_entries == [
        FitsHeaderEntry('SIMPLE', True),
        FitsHeaderEntry('BITPIX', 8),
        FitsHeaderEntry('NAXIS', 0),
        FitsHeaderEntry('EXTEND', True),
        FitsHeaderEntry('DATE', '2011-09-13T15:37:38'),
        FitsHeaderEntry('ORIGIN', 'RHESSI'),
        FitsHeaderEntry('OBSERVER', 'Unknown'),
        FitsHeaderEntry('TELESCOP', 'RHESSI'),
        FitsHeaderEntry('INSTRUME', 'RHESSI'),
        FitsHeaderEntry('OBJECT', 'Sun'),
        FitsHeaderEntry('DATE_OBS', '2002-02-20T11:06:00.000'),
        FitsHeaderEntry('DATE_END', '2002-02-20T11:06:43.330'),
        FitsHeaderEntry('TIME_UNI', 1),
        FitsHeaderEntry('ENERGY_L', 25.0),
        FitsHeaderEntry('ENERGY_H', 40.0),
        FitsHeaderEntry('TIMESYS', '1979-01-01T00:00:00'),
        FitsHeaderEntry('TIMEUNIT', 'd')]


@pytest.mark.slow
def test_entries_from_query_result(query_result):
    entries = list(entries_from_query_result(query_result))
    assert len(entries) == 122
    snd_entry = entries[1]
    expected_entry = DatabaseEntry(
        source='SOHO', provider='SDAC', physobs='intensity',
        fileid='/archive/soho/private/data/processed/eit/lz/2001/01/efz20010101.070014',
        observation_time_start=datetime(2001, 1, 1, 7, 0, 14),
        observation_time_end=datetime(2001, 1, 1, 7, 0, 21),
        instrument='EIT', size=2059.0, waveunit='Angstrom', wavemin=171.0,
        wavemax=171.0)
    assert snd_entry == expected_entry

{'fraction_non_alphanumeric': 0.1472, 'fraction_numerical': 0.05643636363636364, 'mean_word_length': 4.371875, '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': '1866805', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2329, 'n_words': 407}