def test_add(self):
        """ Create a list with two SerialObjects. Test if for each list one infection object is created (so not only one
         object that is referenced twice. """

        # create infection and add to individuals
        infection_init = {
            'suid': {
                'id': 123
            },
            "duration": 123,
            "incubation_timer": 456
        }
        new_infection = change_serialized_population.loadInfection(
            from_file="infection.json")
        new_infection.update(infection_init.items())

        list_temp = [
            dtkFileSupport.SerialObject({"test_list": []}),
            dtkFileSupport.SerialObject({"test_list": []})
        ]
        change_serialized_population.add(list_temp, "test_list", new_infection)

        a = list_temp[0]["test_list"]
        b = list_temp[1]["test_list"]

        success_ref = list_temp[0]["test_list"] is not list_temp[1][
            "test_list"]
        list_temp[0]["test_list"][0]["duration"] = 999999
        success_value = not list_temp[0]["test_list"][0][
            "duration"] == list_temp[1]["test_list"][0]["duration"]
        self.assertTrue(success_ref and success_value, "Error")
Пример #2
0
    def test_round_trip(self):

        source = dft.DtkFileV4()
        source.author = 'dtkFileTests'
        source.compression = dft.SNAPPY     # Choose something other than the default
        simulation = support.SerialObject({"enable_spatial_output": False, "Run_Number": 42, "enable_property_output": False, "infectionSuidGenerator": {"next_suid": {"id": 1}, "rank": 0, "numtasks": 1}, "__class__": "Simulation", "campaignFilename": "campaign.json", "nodes": [], "loadbalance_filename": "", "serializationMask": 3, "individualHumanSuidGenerator": {"next_suid": {"id": 1001}, "rank": 0, "numtasks": 1}, "sim_type": 1, "enable_default_report": True, "enable_event_report": False, "Ind_Sample_Rate": 1, "demographic_tracking": False})
        node = support.SerialObject({"demographics_other": False, "birth_rate_sinusoidal_forcing_phase": 0, "sample_rate_20_plus": 0, "max_sampling_cell_pop": 0, "infectivity_boxcar_end_time": 0, "sample_rate_18mo_4yr": 0, "__class__": "Node", "infectivity_boxcar_start_time": 0, "demographics_gender": True, "individualHumans": [{"migration_is_destination_new_home": False, "home_node_id": {"id": 1}, "waiting_for_family_trip": False, "migration_will_return": True, "waypoints": [], "family_migration_type": 0, "Inf_Sample_Rate": 1, "migration_outbound": True, "m_mc_weight": 11, "migration_time_until_trip": 0, "StateChange": 0, "suid": {"id": 1}, "leave_on_family_trip": False, "interventions": {"drugVaccineReducedTransmit": 1, "drugVaccineReducedAcquire": 1, "__class__": "InterventionsContainer", "drugVaccineReducedMortality": 1, "interventions": []}, "migration_destination": {"id": 0}, "__class__": "IndividualHuman", "infectiousness": 0, "migration_mod": 1, "waypoints_trip_type": [], "m_age": 9588.48, "m_is_infected": False, "m_daily_mortality_rate": 0, "cumulativeInfs": 0, "family_migration_time_at_destination": 0, "family_migration_destination": {"id": 0}, "m_new_infection_state": 0, "migration_time_at_destination": 0, "family_migration_is_destination_new_home": False, "migration_type": 0, "max_waypoints": 0, "pregnancy_timer": 0, "family_migration_time_until_trip": 0, "is_pregnant": False, "susceptibility": {"trandecayoffset": 0, "age": 9588.48, "__class__": "Susceptibility", "acqdecayoffset": 0, "mod_mortality": 1, "mod_acquire": 1, "mod_transmit": 1, "mortdecayoffset": 0}, "is_on_family_trip": False, "infections": [], "above_poverty": 0, "Properties": [], "m_gender": 0}], "serializationMask": 3, "infectivity_sinusoidal_forcing_amplitude": 1, "birth_rate_boxcar_start_time": 0, "x_birth": 2.718281828, "sample_rate_immune": 0, "population_density_infectivity_correction": 0, "sample_rate_0_18mo": 0, "population_scaling": 0, "demographics_birth": False, "suid": {"id": 1}, "birth_rate_boxcar_forcing_amplitude": 1, "population_scaling_factor": 1, "birth_rate_boxcar_end_time": 0, "ind_sampling_type": 0, "vital_birth_time_dependence": 0, "externalId": 314159265, "age_initialization_distribution_type": 1, "infectivity_sinusoidal_forcing_phase": 0, "immune_threshold_for_downsampling": 0, "sample_rate_5_9": 0, "home_individual_ids": [{"key": 1, "value": {"id": 1}}], "population_density_c50": 0, "sample_rate_birth": 0, "birth_rate_sinusoidal_forcing_amplitude": 1, "infectivity_boxcar_forcing_amplitude": 1, "vital_birth": False, "maternal_transmission": False, "vital_birth_dependence": 1, "infectivity_scaling": 0, "animal_reservoir_type": 0, "zoonosis_rate": 0, "sample_rate_10_14": 0, "sample_rate_15_19": 0})
        source.objects.append(simulation)
        source.objects.append(node)
        handle, filename = tempfile.mkstemp()
        os.close(handle)    # Do not need this, just the filename
        dft.write(source, filename)

        dest = dft.read(filename)
        self.assertEqual('dtkFileTests', dest.author)
        self.assertEqual(dft.SNAPPY, dest.compression)
        simulation = dest.simulation
        self.assertEqual(False, simulation.enable_spatial_output)
        self.assertEqual(42, simulation.Run_Number)
        self.assertEqual(1001, simulation.individualHumanSuidGenerator.next_suid.id)
        self.assertEqual(1, simulation.sim_type)
        self.assertEqual(True, simulation.enable_default_report)
        node = dest.nodes[0]
        self.assertEqual(314159265, node.externalId)
        self.assertEqual(False, node.demographics_other)
        self.assertEqual(True, node.demographics_gender)
        self.assertEqual(2.718281828, node.x_birth)
        individual = node.individualHumans[0]
        self.assertEqual(11, individual.m_mc_weight)
        self.assertEqual(1, individual.suid.id)
        self.assertEqual(9588.48, individual.m_age)
        self.assertEqual(0, individual.m_gender)
        os.remove(filename)

        return
Пример #3
0
    def test_add(self):
        Expected_Number_Added_Infections = 5

        # create infection and add to individuals
        infection_init = {"duration": 123, "incubation_timer": 456}
        new_infection = change_serialized_population.createInfection(
            "Generic", {'suid': {
                'id': 123
            }}, infection_init)
        list_temp = [
            dtkFileSupport.SerialObject({"test_list": []}),
            dtkFileSupport.SerialObject({"test_list": []})
        ]
        change_serialized_population.add(list_temp, "test_list", new_infection)

        a = list_temp[0]["test_list"]
        b = list_temp[1]["test_list"]

        success_ref = list_temp[0]["test_list"] is not list_temp[1][
            "test_list"]
        list_temp[0]["test_list"][0]["duration"] = 999999
        success_value = not list_temp[0]["test_list"][0][
            "duration"] == list_temp[1]["test_list"][0]["duration"]
        self.assertTrue(success_ref and success_value, "Error")