예제 #1
0
def test_convert_int_to_hex():
    """
    Integers should be converted into 3-digit hex values.
    """

    assert int_to_dir(0) == '000'
    assert int_to_dir(16) == '010'
    assert int_to_dir(256) == '100'
def test_convert_int_to_hex():

    """
    Integers should be converted into 3-digit hex values.
    """

    assert int_to_dir(0) == '000'
    assert int_to_dir(16) == '010'
    assert int_to_dir(256) == '100'
    def add_segments(self, s1=0, s2=4095):
        """
        Add a batch of segments, identified by an offset range.

        Args:
            s1 (int): The first segment.
            s2 (int): The last segment.
        """

        for i in range(s1, s2):
            self.add_segment(int_to_dir(i))
    def add_segments(self, s1=0, s2=4095):

        """
        Add a batch of segments, identified by an offset range.

        Args:
            s1 (int): The first segment.
            s2 (int): The last segment.
        """

        for i in range(s1, s2):
            self.add_segment(int_to_dir(i))
def segment_range(*args):

    """
    Generate a range of segment names.

    Args:
        s1 (int): The first segment.
        s2 (int): The last segment.

    Yields:
        str: The next segment name.
    """

    for i in range(*args):
        yield int_to_dir(i)
예제 #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 assert_segment(corpus, segment, offset):
    """
    Check for a well-formed Segment instance.

    Args:
        corpus (Corpus): The parent corpus.
        segment (Segment): The candidate Segment.
        offset (int): The segment offset.
    """

    # Should be a Segment instance.
    assert isinstance(segment, Segment)

    # Should have the correct path.
    dpath = os.path.join(corpus.path, int_to_dir(offset))
    assert segment.path == dpath
예제 #8
0
파일: corpus.py 프로젝트: overview/osp
    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 assert_segment(corpus, segment, offset):

    """
    Check for a well-formed Segment instance.

    Args:
        corpus (Corpus): The parent corpus.
        segment (Segment): The candidate Segment.
        offset (int): The segment offset.
    """

    # Should be a Segment instance.
    assert isinstance(segment, Segment)

    # Should have the correct path.
    dpath = os.path.join(corpus.path, int_to_dir(offset))
    assert segment.path == dpath