Ejemplo n.º 1
0
    def test_read_url(self):
        """
        Tests that we can read urls.
        """
        results = Dampr.read_input(UrlsInput(["http://www.example.com"])) \
                .filter(lambda line: 'h1' in line) \
                .map(lambda line: line.strip()) \
                .read()

        self.assertEqual(results, ['<h1>Example Domain</h1>'])
Ejemplo n.º 2
0
    def test_read_input(self):
        """
        Tests that custom taps work as expected.
        """

        results = Dampr.read_input(RangeDataset(5), RangeDataset(10)) \
                .fold_by(lambda x: 1, lambda x, y: x + y) \
                .read()

        self.assertEqual(results[0][1], sum(range(5)) + sum(range(10)))
Ejemplo n.º 3
0
    def test_read_input(self):
        """
        Tests that custom taps work as expected.
        """
        class RangeDataset(Dataset):
            def __init__(self, n):
                self.n = n

            def read(self):
                for i in range(self.n):
                    yield i, i

        results = Dampr.read_input(RangeDataset(5), RangeDataset(10)) \
                .fold_by(lambda x: 1, lambda x, y: x + y) \
                .read()

        self.assertEqual(results[0][1], sum(range(5)) + sum(range(10)))