Esempio n. 1
0
    def test_next__plain(self, patched_parse):
        tested = TextDeserializer([''] * 4)

        assert tested.next() == TextLine(1, 'one')
        assert tested.next() == TextLine(2, 'two')
        assert tested.next() == TextLine(3, 'three')
        assert tested.next() == TextLine(4, 'four')
        assert tested.next() is None
Esempio n. 2
0
    def test_next__level(self, patched_parse):
        tested = TextDeserializer(['a', 'b', 'c', 'd'])

        assert tested.next(level=1) == TextLine(1, 'one')
        assert tested.next(level=1) == TextLine(2, 'two')
        assert tested.next(level=1) == TextLine(1, 'three')
        assert tested.next(level=1) is None
        assert tested.next(level=0) == TextLine(0, 'four')
        assert tested.next(level=0) is None
Esempio n. 3
0
    def test_decode_data(self, decode_line_patched, iter_level_patched):
        assert TextDeserializer([]).decode_data(level=2) == {
            'a': 1,
            'b': 2,
            'c': 42,
        }

        iter_level_patched.assert_called_with(2)
Esempio n. 4
0
    def on_open(self):
        path = filedialog.askopenfilename(
            initialdir=gui_const.DEFAULT_SAVE_DIR,
            filetypes=(
                ('images', '*.vi*'),
                ('all files', '*.*'),
            )
        )

        if not path:
            return

        with open(path, mode='rb') as f:
            processors = [x(self) for x in reversed(self.file_processors)]

            try:
                buffer = read_pipeline(f, processors)
            except StopPipelineError as e:
                return messagebox.showerror('Error!', e.message)

            try:
                objects_iterator = TextDeserializer(TextIOWrapper(buffer)).decode()
                image = next(objects_iterator)
                rest_of_data = tuple(objects_iterator)
            except Exception:
                logger.exception('Got unexpected exception while reading a file.')
                return messagebox.showerror('Error!', "Can't open a file.")

        if not isinstance(image, Container):
            logger.error('Unexpected file content.')
            return

        if rest_of_data:
            logger.warning('Following records will be ignored: %s', rest_of_data)

        self.figures = image
        self._update_figures()
Esempio n. 5
0
    def test_decode(self, figure_patched, container_patched, next_patched):
        assert tuple(TextDeserializer([]).decode(level=3)) == ('C', 'F', 'F',
                                                               'F', 'C')

        figure_patched.assert_called_with(class_name='C', level=4)
        container_patched.assert_called_with(level=4)
Esempio n. 6
0
    def test_decode_data_line(self, patched_method):
        assert TextDeserializer(
            []).decode_data_line('name: Vasia ') == ('name', 'V for Vendetta')

        patched_method.assert_called_once_with('Vasia')
Esempio n. 7
0
 def test_decode_value(self, value, expected):
     assert TextDeserializer([]).decode_value(value) == expected
Esempio n. 8
0
    def test_iter_level(self, patched_method):
        assert tuple(TextDeserializer([]).iter_level(1)) == (1, 2, 3, 4, 5)

        patched_method.assert_called_with(level=1)