def test_collision(self, massive_object): note = model.Object() assert massive_object.is_collision(note.position) note = model.Object(position=(1.1, 0)) assert not massive_object.is_collision(note.position)
def _make_tag(self, name): check_tag_name(name) try: return self.get_tag(name) except KeyError: obj = model.Object(TYPE_CLASSIFIER, name) self.session.add(obj) return model_obj_to_higu_obj(self, obj)
def __register_file(self, path, name_policy): import mimetypes name = os.path.split(path)[1].decode(sys.getfilesystemencoding()) ext = os.path.splitext(name)[1] assert ext[0] == '.' ext = ext[1:] details = calculate_details(path) mime_type = mimetypes.guess_type(path, strict=False)[0] streams = self.lookup_streams_by_details(*details) new_stream = False if (len(streams) == 0): obj = model.Object(TYPE_FILE) self.session.add(obj) stream = model.Stream(obj, '.', model.SP_NORMAL, None, ext, mime_type) stream.set_details(*details) self.session.add(stream) obj.root_stream = stream f = model_obj_to_higu_obj(self, obj) stream = model_stream_to_higu_stream(self, stream) new_stream = True self.session.flush() f._on_created(stream) else: stream = streams[0] if (stream.stream.mime_type is None): stream.stream.mime_type = mime_type f = stream._get_file() if (name_policy == NAME_POLICY_DONT_REGISTER): log = model.StreamLog(stream.stream, 'hdbfs:register', None, None) else: log = model.StreamLog(stream.stream, 'hdbfs:register', None, name) self.session.add(log) if (name_policy == NAME_POLICY_SET_ALWAYS or (name_policy == NAME_POLICY_SET_IF_UNDEF and f.obj.name is None)): f.obj.name = name if (not stream._verify()): self.imgdb.load_data(path, stream.stream.stream_id, stream.stream.priority, stream.stream.extension) return f, stream, new_stream
def test_acceleration(self): note = model.Object(position=(0., 0.), velocity=(0., 0.), acceleration=(1., 0.)) note.step_forward() assert note.velocity == (1., 0.) assert note.position == (1., 0.) note.step_forward() assert note.velocity == (2, 0.) assert note.position == (3, 0.)
def __create_album(self, tags=[], name=None, text=None): album = model.Object(TYPE_ALBUM) self.session.add(album) album = model_obj_to_higu_obj(self, album) if (name is not None): album.obj.name = make_unicode(name) if (text is not None): album.obj['text'] = make_unicode(text) for t in tags: album._assign(t, None) return album
def copy_tag(self, tag, target): with self._access(write=True): check_tag_name(target) c = self.get_tag(tag).obj try: d = self.get_tag(target).obj except KeyError: d = model.Object(TYPE_CLASSIFIER, target) self.session.add(d) for rel in c.child_rel: rel_copy = model.Relation(rel.sort) rel_copy.parent_obj = d rel_copy.child_obj = rel.child_obj
def test_double_movement(self): note = model.Object(position=(0., 0.), velocity=(1., 1.)) note.step_forward() note.step_forward() assert note.position == (2, 2)
def test_left_movement(self): note = model.Object(position=(0., 0.), velocity=(0., -1.)) note.step_forward() assert note.position == (0., -1.)
def make_note_up(): return model.Object(velocity=(0, 1))
def make_note_across(): return model.Object(velocity=(1, 0))
def fire(self): self.shots.append( model.Object(position=self.position, velocity=(0, config.SHOT_SPEED)))