def test_cache(self): config = Config(db_url='sqlite://') Session = startup(config) cached_stringify = Cache(stringify, Session, clean=False) self._assert(stringify(1, 2, three=4), "(1, 2) {'three': 4}") self._assert(cached_stringify(1, 2, three=4), "(1, 2) {'three': 4}") assert cached_stringify.hits == 0, cached_stringify.hits assert cached_stringify.misses == 1, cached_stringify.misses self._assert(cached_stringify(1, 2, three=4), "(1, 2) {'three': 4}") assert cached_stringify.hits == 1, cached_stringify.hits assert cached_stringify.misses == 1, cached_stringify.misses assert CacheCleaner(Session, standalone=False)._clean_least_used() == 0 self._assert(cached_stringify(1, 2, three=4), "(1, 2) {'three': 4}") assert cached_stringify.hits == 2, cached_stringify.hits assert cached_stringify.misses == 1, cached_stringify.misses assert CacheCleaner(Session, max_size=1, standalone=False)._clean_least_used() == 1 self._assert(cached_stringify(1, 2, three=4), "(1, 2) {'three': 4}") assert cached_stringify.hits == 2, cached_stringify.hits assert cached_stringify.misses == 2, cached_stringify.misses assert CacheCleaner(Session, standalone=False)._clean_expired() == 0 self._assert(cached_stringify(1, 2, three=4), "(1, 2) {'three': 4}") assert cached_stringify.hits == 3, cached_stringify.hits assert cached_stringify.misses == 2, cached_stringify.misses sleep(1) assert CacheCleaner(Session, max_lifetime=1, standalone=False)._clean_expired() == 1 self._assert(cached_stringify(1, 2, three=4), "(1, 2) {'three': 4}") assert cached_stringify.hits == 3, cached_stringify.hits assert cached_stringify.misses == 3, cached_stringify.misses
def test_db(self): Session = startup(Config(db_url='sqlite:///', modules=['uykff.nest'])) session = Session() nest_artist = NestArtist() session.add(nest_artist) session.commit() artist = Artist(name='bob', tagger_name=NestTagger.TAGGER_NAME, tag_id=nest_artist.id) nest_artist.artist = artist session.add(artist) session.commit() session = Session() artists = session.query(Artist).all() assert len(artists) == 1, artists nest_artists = session.query(NestArtist).all() assert len(nest_artists) == 1, nest_artists assert nest_artists[0].artist == artists[0]
def test_catalogue(self): Session = startup(Config(db_url='sqlite:///')) session = Session() artist = Artist(name='bob', tagger_name='tagger', tag_id=0) session.add(artist) track1 = Track(name='track1', artist=artist, number='1', file='file1', modified=datetime.today()) session.add(track1) track2 = Track(name='track2', artist=artist, number='2', file='file2', modified=datetime.today()) session.add(track2) album = Album(name='album', tracks=[track1, track2]) session.add(album) session.commit() session = Session() artists = session.query(Artist).all() assert len(artists) == 1, artists assert len(artists[0].tracks) == 2, artists[0].tracks tracks = session.query(Track).all() assert len(tracks) == 2, tracks albums = session.query(Album).all() assert len(albums) == 1, albums assert tracks[0].album == albums[0]
def do_directory(self, file): config = Config(mp3_path=join(parent(__file__), file), db_url='sqlite:///') # config = Config(mp3_path=join(parent(__file__), file), db_url='sqlite:////tmp/test.sql') session = startup(config)() scan(session, config) return session, config