Пример #1
0
 def instantiate_from(self, filename):
     datadir = os.environ.get('FHIR_UNITTEST_DATADIR') or \
               os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'fhir-parser', 'downloads'))
     with io.open(os.path.join(datadir, filename), 'r',
                  encoding='utf-8') as handle:
         js = json.load(handle)
         self.assertEqual("Location", js["resourceType"])
     return location.Location(js)
Пример #2
0
    def testLocation2(self):
        inst = self.instantiate_from("location-example-room.json")
        self.assertIsNotNone(inst,
                             "Must have instantiated a Location instance")
        self.implLocation2(inst)

        js = inst.as_json()
        self.assertEqual("Location", js["resourceType"])
        inst2 = location.Location(js)
        self.implLocation2(inst2)
Пример #3
0
def test_location():
    sample_hb_1 = location.Location(model, '', '')
    sample_hb_2 = location.Location(model, '', '')
    assert sample_hb_1.strid == 'Location'
    # Tests get_parameter
    assert sample_hb_1.get_parameter('contagion_probability') == 0.0
    # Tests set_custom_parameter
    sample_hb_1.set_custom_parameters([('contagion_probability', 1.0)],
                                      {'contagion_probability': 1.0})
    assert sample_hb_1.get_parameter('contagion_probability') == 1.0
    # Test move_to
    sample_human_1 = Human.factory(covid_model=model, forced_age=20)
    sample_hb_1.humans.append(sample_human_1)
    assert sample_human_1 in sample_hb_1.humans
    assert not sample_hb_2.humans
    sample_hb_1.move_to(sample_human_1, sample_hb_2)
    assert sample_human_1 not in sample_hb_1.humans
    assert sample_human_1 in sample_hb_2.humans
    # Test check_spreading
    assert check_spread(sample_hb_1, [SimulationState.POST_WORK_ACTIVITY],
                        check_step=False)
Пример #4
0
 def database_content_init(self, record):
     '''
     This method is used to save the full record to the database.
     '''
     date_pattern = '%Y-%m-%dT%H:%M:%S.%fZ'
     record_items = []
     record_items.append(person.Person(
         record['gender'], record['email'], record['phone'],
         record['cell'], record['nat']))
     base_key = record['name']
     record_items.append(name.Name(
         base_key['title'], base_key['first'],
         base_key['last'], record_items[0]))
     base_key = record['location']
     record_items.append(location.Location(
         base_key['city'], base_key['state'], base_key['country'],
         base_key['postcode'], record_items[0]))
     base_key = record['location']['street']
     record_items.append(street.Street(
         base_key['number'], base_key['name'], record_items[2]))
     base_key = record['location']['coordinates']
     record_items.append(coordinates.Coordinates(
         base_key['latitude'], base_key['longitude'], record_items[2]))
     base_key = record['location']['timezone']
     record_items.append(timezone.Timezone(
         base_key['offset'], base_key['description'], record_items[2]))
     base_key = record['login']
     record_items.append(login.Login(
         base_key['uuid'], base_key['username'], base_key['password'],
         base_key['salt'], base_key['md5'], base_key['sha1'],
         base_key['sha256'], record_items[0]))
     base_key = record['dob']
     record_items.append(dob.Dob(
         datetime.strptime(base_key['date'], date_pattern),
         base_key['age'], base_key['days_to_birthday'], record_items[0]))
     base_key = record['registered']
     record_items.append(registered.Registered(
         datetime.strptime(base_key['date'], date_pattern),
         base_key['age'], record_items[0]))
     base_key = record['id']
     record_items.append(identity.Identity(
         base_key['name'], base_key['value'], record_items[0]))
     self.curr_session.add_all(record_items)
     self.curr_session.commit()
Пример #5
0
@author: Johan
'''
from model import item, gender, location, actor, action


def demasiado_caliente(actor):
    return 'está demasiado caliente para cogerla'


vela = item.Item(name='vela atómica',
                 gender=gender.SingularFemale,
                 limits={'coger': demasiado_caliente})
espada = item.Item(name='espada', gender=gender.SingularFemale)


def jugador_coger(item):
    print 'Coges %s.' % item


jugador = actor.Actor(name='jugador', actions={'coger': jugador_coger})
patio = location.Location(name='patio',
                          gender=gender.SingularMale,
                          content=[espada, vela])

if __name__ == '__main__':
    patio.show()
    print '\n>> coger vela\n'
    action.Coger.execute_player(jugador, vela)
    print '\n>> coger espada\n'
    action.Coger.execute_player(jugador, espada)