def test_file_names(mock_osp):

    """
    Segment#file_names() should generate the file names.
    """

    path = mock_osp.add_segment('000')
    segment = Segment(path)

    # Add 10 files.
    for i in range(10):
        mock_osp.add_file(segment='000', name=str(i))

    names = segment.file_names()

    # Should generate file names.
    for i in range(10):
        assert next(names) == str(i)
예제 #2
0
def test_file_paths(mock_osp):
    """
    Segment#file_names() should generate the full file paths.
    """

    path = mock_osp.add_segment('000')
    segment = Segment(path)

    # Add 10 files.
    for i in range(10):
        mock_osp.add_file(segment='000', name=str(i))

    paths = segment.file_paths()

    # Should generate file paths.
    for i in range(10):
        fpath = os.path.join(path, str(i))
        assert next(paths) == fpath
def test_file_paths(mock_osp):

    """
    Segment#file_names() should generate the full file paths.
    """

    path = mock_osp.add_segment("000")
    segment = Segment(path)

    # Add 10 files.
    for i in range(10):
        mock_osp.add_file(segment="000", name=str(i))

    paths = segment.file_paths()

    # Should generate file paths.
    for i in range(10):
        fpath = os.path.join(path, str(i))
        assert next(paths) == fpath
def test_syllabi(mock_osp):
    """
    Segment#syllabi() should generate Syllabus instances.
    """

    path = mock_osp.add_segment('000')
    segment = Segment(path)

    # Add 10 files.
    for i in range(10):
        mock_osp.add_file(segment='000', name=str(i))

    syllabi = segment.syllabi()

    for i in range(10):

        # Should be a Syllabus instance.
        syllabus = next(syllabi)
        assert isinstance(syllabus, Syllabus)

        # Should wrap the right file.
        fpath = os.path.join(path, str(i))
        assert syllabus.path == fpath
def test_file_count(mock_osp):
    """
    Segment#file_count() should return the number of files.
    """

    path = mock_osp.add_segment('000')
    segment = Segment(path)

    # Add 10 files.
    for i in range(10):
        mock_osp.add_file(segment='000', name=str(i))

    # Should count 10 files.
    assert segment.file_count == 10
예제 #6
0
    def segments(self):
        """
        Generate `Segment` instances for each directory.

        Yields:
            Segment: The next segment.
        """

        for s in range(self.s1, self.s2):

            # Get the segment directory path.
            path = os.path.join(self.path, int_to_dir(s))

            # Only yield segment if the path exists.
            if os.path.exists(path): yield Segment(path)
def test_syllabi(mock_osp):

    """
    Segment#syllabi() should generate Syllabus instances.
    """

    path = mock_osp.add_segment('000')
    segment = Segment(path)

    # Add 10 files.
    for i in range(10):
        mock_osp.add_file(segment='000', name=str(i))

    syllabi = segment.syllabi()

    for i in range(10):

        # Should be a Syllabus instance.
        syllabus = next(syllabi)
        assert isinstance(syllabus, Syllabus)

        # Should wrap the right file.
        fpath = os.path.join(path, str(i))
        assert syllabus.path == fpath