Exemple #1
0
 def setup_serializer(self):
     self.test_dir = mkdtemp()
     self.serial = OutputStreamSerializer([self.test_dir])
     self.filename = "STARS"
     self.content = "123\n456\n789"
     self.expected = [
         line.encode('ascii') for line in self.content.split('\n')
     ]
Exemple #2
0
 def setup_serializer(self):
     self.test_dir = mkdtemp()
     self.serial = OutputStreamSerializer([self.test_dir])
     self.filename = "STARS"
     self.content = "123\n456\n789"
     self.expected = [
         line for line in self.content.split('\n')
     ]
Exemple #3
0
class OutputStreamSerializerTestCase(TestCase):
    @setup
    def setup_serializer(self):
        self.test_dir = mkdtemp()
        self.serial = OutputStreamSerializer([self.test_dir])
        self.filename = "STARS"
        self.content = "123\n456\n789"
        self.expected = [
            line.encode('ascii') for line in self.content.split('\n')
        ]

    @teardown
    def teardown_test_dir(self):
        shutil.rmtree(self.test_dir)

    def _write_contents(self):
        with open(self.serial.full_path(self.filename), 'w') as f:
            f.write(self.content)

    def test_open(self):
        with self.serial.open(self.filename) as fh:
            fh.write(self.content)

        with open(self.serial.full_path(self.filename)) as f:
            assert_equal(f.read(), self.content)

    @suite('integration')
    def test_init_with_output_path(self):
        path = OutputPath(self.test_dir, 'one', 'two', 'three')
        stream = OutputStreamSerializer(path)
        assert_equal(stream.base_path, str(path))

    def test_tail(self):
        self._write_contents()
        assert_equal(self.serial.tail(self.filename), self.expected)

    def test_tail_num_lines(self):
        self._write_contents()
        assert_equal(self.serial.tail(self.filename, 1), self.expected[-1:])

    def test_tail_file_does_not_exist(self):
        file_dne = 'bogusfile123'
        assert_equal(self.serial.tail(file_dne), [])
Exemple #4
0
class TestOutputStreamSerializer(TestCase):
    @setup
    def setup_serializer(self):
        self.test_dir = mkdtemp()
        self.serial = OutputStreamSerializer([self.test_dir])
        self.filename = "STARS"
        self.content = "123\n456\n789"
        self.expected = [
            line for line in self.content.split('\n')
        ]

    @teardown
    def teardown_test_dir(self):
        shutil.rmtree(self.test_dir)

    def _write_contents(self):
        with open(self.serial.full_path(self.filename), 'w') as f:
            f.write(self.content)

    def test_open(self):
        with self.serial.open(self.filename) as fh:
            fh.write(self.content)

        with open(self.serial.full_path(self.filename)) as f:
            assert_equal(f.read(), self.content)

    @suite('integration')
    def test_init_with_output_path(self):
        path = OutputPath(self.test_dir, 'one', 'two', 'three')
        stream = OutputStreamSerializer(path)
        assert_equal(stream.base_path, str(path))

    def test_tail(self):
        self._write_contents()
        assert_equal(self.serial.tail(self.filename), self.expected)

    def test_tail_num_lines(self):
        self._write_contents()
        assert_equal(self.serial.tail(self.filename, 1), self.expected[-1:])

    def test_tail_file_does_not_exist(self):
        file_dne = 'bogusfile123'
        assert_equal(self.serial.tail(file_dne), [])
Exemple #5
0
 def test_init_with_output_path(self):
     path = OutputPath(self.test_dir, 'one', 'two', 'three')
     stream = OutputStreamSerializer(path)
     assert_equal(stream.base_path, str(path))