def test_syllabi(mock_osp): """ Corpus#syllabi() should generate Syllabus instances for all files. """ # 10 segments, each with 10 files. for s in segment_range(10): for i in range(10): mock_osp.add_file(segment=s, name=s + '-' + str(i)) corpus = Corpus(mock_osp.path) syllabi = corpus.syllabi() # Walk segments / files: for s in segment_range(10): for i in range(10): # Should be a Syllabus instance. syllabus = next(syllabi) assert isinstance(syllabus, Syllabus) # Should generate the next file path. name = s + '-' + str(i) path = os.path.join(corpus.path, s, name) assert syllabus.path == path # And stop at the end. assert next(syllabi, False) == False
def test_insert_documents(mock_osp): """ Corpus.insert_documents() should create a row for each syllabus. """ # 10 segments x 10 files. for s in segment_range(10): for i in range(10): mock_osp.add_file(segment=s, name=s + "-" + str(i)) # Insert document rows. Document.insert_documents() # Should create 100 rows. assert Document.select().count() == 100 # All docs should have rows. for s in segment_range(10): for i in range(10): # Path is [segment]/[file] path = s + "/" + s + "-" + str(i) # Query for the document path. query = Document.select().where(Document.path == path) assert query.count() == 1
def test_file_paths(mock_osp): """ Corpus#file_paths() should generate the paths of files in all segments. """ # 10 segments, each with 10 files. for s in segment_range(10): for i in range(10): mock_osp.add_file(segment=s, name=s+'-'+str(i)) corpus = Corpus(mock_osp.path) paths = corpus.file_paths() # Walk segments / files: for s in segment_range(10): for i in range(10): # Should generate the next file path. name = s+'-'+str(i) path = os.path.join(corpus.path, s, name) assert next(paths) == path # And stop at the end. assert next(paths, False) == False
def test_syllabi(mock_osp): """ Corpus#syllabi() should generate Syllabus instances for all files. """ # 10 segments, each with 10 files. for s in segment_range(10): for i in range(10): mock_osp.add_file(segment=s, name=s+'-'+str(i)) corpus = Corpus(mock_osp.path) syllabi = corpus.syllabi() # Walk segments / files: for s in segment_range(10): for i in range(10): # Should be a Syllabus instance. syllabus = next(syllabi) assert isinstance(syllabus, Syllabus) # Should generate the next file path. name = s+'-'+str(i) path = os.path.join(corpus.path, s, name) assert syllabus.path == path # And stop at the end. assert next(syllabi, False) == False
def test_file_count(mock_osp): """ Corpus#file_count should return the number of files in all segments. """ # 10 segments, each with 10 files. for s in segment_range(10): for i in range(10): mock_osp.add_file(segment=s, name=str(i)) corpus = Corpus(mock_osp.path) assert corpus.file_count == 100
def test_file_paths(mock_osp): """ Corpus#file_paths() should generate the paths of files in all segments. """ # 10 segments, each with 10 files. for s in segment_range(10): for i in range(10): mock_osp.add_file(segment=s, name=s + '-' + str(i)) corpus = Corpus(mock_osp.path) paths = corpus.file_paths() # Walk segments / files: for s in segment_range(10): for i in range(10): # Should generate the next file path. name = s + '-' + str(i) path = os.path.join(corpus.path, s, name) assert next(paths) == path # And stop at the end. assert next(paths, False) == False