# Path: pydoop/mapreduce/binary_protocol.py
# OUTPUT = 50
# 
# PARTITIONED_OUTPUT = 51


import io
import os
import shutil
import struct
import tempfile
import unittest
import uuid
import pydoop.sercore as sercore
from random import randint
from pydoop.mapreduce.binary_protocol import OUTPUT, PARTITIONED_OUTPUT
INT64_MAX = 2**63 - 1

# TODO: from pydoop.test_utils import UNI_CHR
UNI_CHR = u'\N{CYRILLIC CAPITAL LETTER O WITH DIAERESIS}'


class TestFileInStream(unittest.TestCase):

    def setUp(self):
        with io.open(__file__, "rb") as f:
            self.data = f.read()

    def test_from_path(self):
        with sercore.FileInStream(__file__) as s:
            self.__check_stream(s)

    def test_from_file(self):
        with io.open(__file__, "rb") as f:
            with sercore.FileInStream(f) as s:
                self.__check_stream(s)

    def test_errors(self):
        with self.assertRaises(IOError):
            sercore.FileInStream(uuid.uuid4().hex)
        with sercore.FileInStream(__file__) as s:
            s.skip(len(self.data))
            with self.assertRaises(IOError):
                s.read(1)

    def __check_stream(self, s):

# Path: pydoop/mapreduce/binary_protocol.py
# OUTPUT = 50
# 
# PARTITIONED_OUTPUT = 51


# Path: test/sercore/test_streams.py
import io
import os
import shutil
import struct
import tempfile
import unittest
import uuid
import pydoop.sercore as sercore
from random import randint
from pydoop.mapreduce.binary_protocol import OUTPUT, PARTITIONED_OUTPUT

INT64_MAX = 2**63 - 1

# TODO: from pydoop.test_utils import UNI_CHR
UNI_CHR = u'\N{CYRILLIC CAPITAL LETTER O WITH DIAERESIS}'


class TestFileInStream(unittest.TestCase):

    def setUp(self):
        with io.open(__file__, "rb") as f:
            self.data = f.read()

    def test_from_path(self):
        with sercore.FileInStream(__file__) as s:
            self.__check_stream(s)

    def test_from_file(self):
        with io.open(__file__, "rb") as f:
            with sercore.FileInStream(f) as s:
                self.__check_stream(s)

    def test_errors(self):
        with self.assertRaises(IOError):
            sercore.FileInStream(uuid.uuid4().hex)
        with sercore.FileInStream(__file__) as s:
            s.skip(len(self.data))
            with self.assertRaises(IOError):
                s.read(1)

    def __check_stream(self, s):

        self.assertEqual(s.read(10), self.data[:10])