<commit_before>from __future__ import print_function, division

import os
import tempfile

import h5py
import pytest
import numpy as np

from .. import Model
from ...util.functions import random_filename
from ...dust import IsotropicDust
from .test_helpers import get_test_model_noimaging, get_test_dust


def test_write_noname_nofilename():
    m = Model()
    with pytest.raises(ValueError) as e:
        m.write()
    assert e.value.args[0] == "filename= has not been specified and model has no name"


def test_write_nogrid():
    m = Model()
    with pytest.raises(Exception) as e:
        m.write('test')
    assert e.value.args[0] == 'No coordinate grid has been set up'


class TestWriteDustCopy(object):

    def setup_method(self, method):

        self.dust_file = random_filename()
        self.dust = get_test_dust()

        self.density = np.array([[[1.]]])

        self.model = get_test_model_noimaging()

    def test_copy_filename(self):
        self.dust.write(self.dust_file)
        self.model.add_density_grid(self.density, self.dust_file)
        self.model.write(random_filename(), copy=True)
        self.model.run(random_filename())

    def test_copy_object(self):
        self.model.add_density_grid(self.density, self.dust)
        self.model.write(random_filename(), copy=True)
        self.model.run(random_filename())
<commit_msg>Added a few tests for numbers of photons<commit_after>from __future__ import print_function, division

import os
import tempfile

import h5py
import pytest
import numpy as np

from .. import Model
from ...util.functions import random_filename
from ...dust import IsotropicDust
from .test_helpers import get_test_model_noimaging, get_test_dust


def test_write_noname_nofilename():
    m = Model()
    with pytest.raises(ValueError) as e:
        m.write()
    assert e.value.args[0] == "filename= has not been specified and model has no name"


def test_write_nogrid():
    m = Model()
    with pytest.raises(Exception) as e:
        m.write('test')
    assert e.value.args[0] == 'No coordinate grid has been set up'


def test_write_nophotons():
    m = Model()
    m.set_cartesian_grid([-1., 1.], [-1., 1.], [-1., 1.])
    with pytest.raises(Exception) as e:
        m.write('test')
    assert e.value.args[0] == 'Photon numbers not set'


def test_write_incomplete_photons_1():
    m = Model()
    m.set_cartesian_grid([-1., 1.], [-1., 1.], [-1., 1.])
    with pytest.raises(Exception) as e:
        m.set_n_photons(initial=1)
    assert e.value.args[0] == '[n_photons] imaging should bet set'


def test_write_incomplete_photons_2():
    m = Model()
    m.set_cartesian_grid([-1., 1.], [-1., 1.], [-1., 1.])
    with pytest.raises(Exception) as e:
        m.set_n_photons(imaging=1)
    assert e.value.args[0] == '[n_photons] initial should be set since the initial iterations are being computed'


class TestWriteDustCopy(object):

    def setup_method(self, method):

        self.dust_file = random_filename()
        self.dust = get_test_dust()

        self.density = np.array([[[1.]]])

        self.model = get_test_model_noimaging()

    def test_copy_filename(self):
        self.dust.write(self.dust_file)
        self.model.add_density_grid(self.density, self.dust_file)
        self.model.write(random_filename(), copy=True)
        self.model.run(random_filename())

    def test_copy_object(self):
        self.model.add_density_grid(self.density, self.dust)
        self.model.write(random_filename(), copy=True)
        self.model.run(random_filename())

{'fraction_non_alphanumeric': 0.121006502685892, 'fraction_numerical': 0.009329940627650551, 'mean_word_length': 3.3146341463414632, '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': '6188671', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1167, 'n_words': 279}