-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from PickwickSoft/bugfix/fix-base-stream-knows…
…-subclasses Add stream converter
- Loading branch information
Showing
9 changed files
with
120 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from pystreamapi.__stream import Stream | ||
from pystreamapi._streams.error.__levels import ErrorLevel | ||
|
||
__version__ = "0.3.1" | ||
__version__ = "0.3.2" | ||
__all__ = ["Stream", "ErrorLevel"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from pystreamapi._streams.__base_stream import BaseStream | ||
from pystreamapi._streams.__parallel_stream import ParallelStream | ||
from pystreamapi._streams.__sequential_stream import SequentialStream | ||
from pystreamapi._streams.numeric.__numeric_base_stream import NumericBaseStream | ||
from pystreamapi._streams.numeric.__parallel_numeric_stream import ParallelNumericStream | ||
from pystreamapi._streams.numeric.__sequential_numeric_stream import SequentialNumericStream | ||
|
||
|
||
class StreamConverter: | ||
"""Class for converting streams to other types of streams.""" | ||
|
||
@staticmethod | ||
def to_numeric_stream(stream: BaseStream) -> NumericBaseStream: | ||
"""Converts a stream to a numeric stream.""" | ||
if isinstance(stream, SequentialStream): | ||
stream.__class__ = SequentialNumericStream | ||
if isinstance(stream, ParallelStream): | ||
stream.__class__ = ParallelNumericStream | ||
return stream | ||
|
||
@staticmethod | ||
def to_parallel_stream(stream: BaseStream) -> ParallelStream: | ||
"""Converts a stream to a parallel stream.""" | ||
if isinstance(stream, SequentialNumericStream): | ||
stream.__class__ = ParallelNumericStream | ||
elif isinstance(stream, SequentialStream): | ||
stream.__class__ = ParallelStream | ||
return stream | ||
|
||
@staticmethod | ||
def to_sequential_stream(stream: BaseStream) -> SequentialStream: | ||
"""Converts a stream to a sequential stream.""" | ||
if isinstance(stream, ParallelNumericStream): | ||
stream.__class__ = SequentialNumericStream | ||
elif isinstance(stream, ParallelStream): | ||
stream.__class__ = SequentialStream | ||
return stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from unittest import TestCase | ||
|
||
from pystreamapi._streams.__parallel_stream import ParallelStream | ||
from pystreamapi._streams.__sequential_stream import SequentialStream | ||
from pystreamapi._streams.numeric.__parallel_numeric_stream import ParallelNumericStream | ||
from pystreamapi._streams.numeric.__sequential_numeric_stream import SequentialNumericStream | ||
|
||
|
||
class TestStreamConverter(TestCase): | ||
|
||
def test_convert_to_numeric_stream_sequential(self): | ||
stream = SequentialStream(["1", "2", "3"]).map_to_int() | ||
self.assertIsInstance(stream, SequentialNumericStream) | ||
|
||
def test_convert_to_numeric_stream_parallel(self): | ||
stream = ParallelStream(["1", "2", "3"]).map_to_int() | ||
self.assertIsInstance(stream, ParallelNumericStream) | ||
|
||
def test_convert_to_numeric_stream_numeric_parallel(self): | ||
stream = ParallelNumericStream(["1", "2", "3"]).map_to_int() | ||
self.assertIsInstance(stream, ParallelNumericStream) | ||
|
||
def test_convert_to_parallel_stream_sequential(self): | ||
stream = SequentialStream(["1", "2", "3"]).parallel() | ||
self.assertIsInstance(stream, ParallelStream) | ||
|
||
def test_convert_to_parallel_stream_sequential_numeric(self): | ||
stream = SequentialNumericStream(["1", "2", "3"]).parallel() | ||
self.assertIsInstance(stream, ParallelNumericStream) | ||
|
||
def test_convert_to_parallel_stream_parallel(self): | ||
stream = ParallelStream(["1", "2", "3"]).parallel() | ||
self.assertIsInstance(stream, ParallelStream) | ||
|
||
def test_convert_to_parallel_stream_parallel_numeric(self): | ||
stream = ParallelNumericStream(["1", "2", "3"]).parallel() | ||
self.assertIsInstance(stream, ParallelNumericStream) | ||
|
||
def test_convert_to_sequential_stream_sequential(self): | ||
stream = SequentialStream(["1", "2", "3"]).sequential() | ||
self.assertIsInstance(stream, SequentialStream) | ||
|
||
def test_convert_to_sequential_stream_sequential_numeric(self): | ||
stream = SequentialNumericStream(["1", "2", "3"]).sequential() | ||
self.assertIsInstance(stream, SequentialNumericStream) | ||
|
||
def test_convert_to_sequential_stream_parallel(self): | ||
stream = ParallelStream(["1", "2", "3"]).sequential() | ||
self.assertIsInstance(stream, SequentialStream) | ||
|
||
def test_convert_to_sequential_stream_parallel_numeric(self): | ||
stream = ParallelNumericStream(["1", "2", "3"]).sequential() | ||
self.assertIsInstance(stream, SequentialNumericStream) |