<commit_before>from ..patch_headers import *
from tempfile import mkdtemp
from os import path
from shutil import rmtree
import numpy as np

test_tuple = (1,2,3.1415)
_test_dir = ''
def test_sexagesimal_string():
    assert sexagesimal_string(test_tuple) == '01:02:03.14'

def test_sexagesimal_string_with_sign():
    assert sexagesimal_string(test_tuple, sign=True) == '+01:02:03.14'

def test_sexagesimal_string_with_precision():
    assert sexagesimal_string(test_tuple, precision=3) == '01:02:03.142'

def test_sexagesimal_string_with_precision_and_sign():
    assert sexagesimal_string(test_tuple, sign=True, precision=3) == '+01:02:03.142'

def test_read_object_list():
    observer, objects = read_object_list(dir=_test_dir)
    assert len(objects) == 2
    assert objects[0] == 'ey uma'
    assert objects[1] == 'm101'
    assert observer == 'Ima Observer'

def test_data_is_unmodified():
    """No changes should be made to the data."""
    from shutil import copy

    copy('data/uint16.fit', _test_dir)
    new_ext = '_new'
    patch_headers(_test_dir,new_file_ext=new_ext)
    fname = path.join(_test_dir,'uint16')
    fname_new = fname+ new_ext
    orig = pyfits.open(fname+'.fit')
    print fname, fname_new
    modified = pyfits.open(fname_new+'.fit')
    assert np.all(orig[0].data == modified[0].data)
    
def setup():
    global _test_dir
    
    _test_dir = mkdtemp()
    to_write = '# comment 1\nIma Observer\n# comment 2\ney uma\nm101'
    object_file = open(path.join(_test_dir,'obsinfo.txt'),'wb')
    object_file.write(to_write)

def teardown():
    global _test_dir<commit_msg>Test that adding object information does not modify data.<commit_after>from ..patch_headers import *
from tempfile import mkdtemp
from os import path
from shutil import rmtree
import numpy as np

test_tuple = (1,2,3.1415)
_test_dir = ''
def test_sexagesimal_string():
    assert sexagesimal_string(test_tuple) == '01:02:03.14'

def test_sexagesimal_string_with_sign():
    assert sexagesimal_string(test_tuple, sign=True) == '+01:02:03.14'

def test_sexagesimal_string_with_precision():
    assert sexagesimal_string(test_tuple, precision=3) == '01:02:03.142'

def test_sexagesimal_string_with_precision_and_sign():
    assert sexagesimal_string(test_tuple, sign=True, precision=3) == '+01:02:03.142'

def test_read_object_list():
    observer, objects = read_object_list(dir=_test_dir)
    assert len(objects) == 2
    assert objects[0] == 'ey uma'
    assert objects[1] == 'm101'
    assert observer == 'Ima Observer'

def test_data_is_unmodified_by_patch_headers():
    """No changes should be made to the data."""
    new_ext = '_new'
    patch_headers(_test_dir,new_file_ext=new_ext)
    fname = path.join(_test_dir,'uint16')
    fname_new = fname+ new_ext
    orig = pyfits.open(fname+'.fit')
    modified = pyfits.open(fname_new+'.fit')
    assert np.all(orig[0].data == modified[0].data)

def test_data_is_unmodified_by_adding_object():
    new_ext = '_obj'
    patch_headers(_test_dir,new_file_ext=new_ext)
    add_object_info(_test_dir, new_file_ext=new_ext)
    fname = path.join(_test_dir,'uint16')
    fname_new = fname+ new_ext + new_ext
    orig = pyfits.open(fname+'.fit')
    modified = pyfits.open(fname_new+'.fit')
    assert np.all(orig[0].data == modified[0].data)
    
    
def setup():
    global _test_dir
    from shutil import copy

    _test_dir = mkdtemp()
    to_write = '# comment 1\nIma Observer\n# comment 2\ney uma\nm101'
    object_file = open(path.join(_test_dir,'obsinfo.txt'),'wb')
    object_file.write(to_write)
    copy(path.join('data', 'uint16.fit'), _test_dir)

def teardown():
    global _test_dir
{'fraction_non_alphanumeric': 0.12294182217343579, 'fraction_numerical': 0.03402854006586169, 'mean_word_length': 4.625, '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': '3192556', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1306, 'n_words': 263}