diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..a0c19b2 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,5 @@ +[run] +source = javaobj/ + +[report] +include = javaobj/* diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 9160059..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -service_name: travis-ci diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..826aa59 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,47 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: CI Build + +on: + push: + branches: '**' + tags: '**' + pull_request: + branches: '**' + +jobs: + build: + timeout-minutes: 10 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest coverage + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=110 --statistics + - name: Test + run: | + coverage run -m pytest + - name: Coveralls + env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + run: | + pip install coveralls + coveralls diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8525272..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: python -python: - - "2.7" - - "3.4" - - "3.5" - - "3.6" - -sudo: false - -install: - - pip install nose coverage coveralls - - pip install pytest>=2.7.3 --upgrade - - pip install -r requirements.txt - -script: - - nosetests -v --with-coverage --cover-package=javaobj tests - -after_success: - - coveralls diff --git a/README.md b/README.md index 77e649f..4385a0b 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,9 @@ # javaobj-py3 -
+[](https://pypi.python.org/pypi/javaobj-py3/) +[](https://pypi.python.org/pypi/javaobj-py3/) +[](https://github.com/tcalmant/python-javaobj/actions/workflows/build.yml) +[](https://coveralls.io/r/tcalmant/python-javaobj?branch=master) *python-javaobj* is a python library that provides functions for reading and writing (writing is WIP currently) Java objects serialized or will be diff --git a/javaobj/__init__.py b/javaobj/__init__.py index bf1ca67..d1b146d 100644 --- a/javaobj/__init__.py +++ b/javaobj/__init__.py @@ -13,12 +13,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/constants.py b/javaobj/constants.py index ebad6a0..d4dd1cb 100644 --- a/javaobj/constants.py +++ b/javaobj/constants.py @@ -4,12 +4,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ ) # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/modifiedutf8.py b/javaobj/modifiedutf8.py index bba2fa9..ac29ce5 100644 --- a/javaobj/modifiedutf8.py +++ b/javaobj/modifiedutf8.py @@ -11,7 +11,7 @@ :authors: Scott Stephens (@swstephe), @guywithface :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha """ @@ -21,7 +21,7 @@ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/utils.py b/javaobj/utils.py index 83593f0..2d6f761 100644 --- a/javaobj/utils.py +++ b/javaobj/utils.py @@ -7,12 +7,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v1/__init__.py b/javaobj/v1/__init__.py index 8c0d601..cc4aaaa 100644 --- a/javaobj/v1/__init__.py +++ b/javaobj/v1/__init__.py @@ -4,12 +4,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v1/beans.py b/javaobj/v1/beans.py index 73b297d..bf867bb 100644 --- a/javaobj/v1/beans.py +++ b/javaobj/v1/beans.py @@ -5,12 +5,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ ) # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v1/core.py b/javaobj/v1/core.py index 2fbe3c4..ae5eeb5 100644 --- a/javaobj/v1/core.py +++ b/javaobj/v1/core.py @@ -13,12 +13,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ ) # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v1/marshaller.py b/javaobj/v1/marshaller.py index 92b376e..9e5bdeb 100644 --- a/javaobj/v1/marshaller.py +++ b/javaobj/v1/marshaller.py @@ -13,12 +13,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -76,7 +76,7 @@ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format @@ -141,6 +141,9 @@ def writeObject(self, obj): # pylint:disable=C0103 if isinstance(obj, JavaArray): # Deserialized Java array self.write_array(obj) + elif isinstance(obj, JavaByteArray): + # Deserialized Java byte array + self.write_array(obj) elif isinstance(obj, JavaEnum): # Deserialized Java Enum self.write_enum(obj) @@ -537,6 +540,8 @@ def _write_value(self, raw_field_type, value): self.write_object(value) elif isinstance(value, JavaString): self.write_string(value) + elif isinstance(value, JavaClass): + self.write_class(value) elif isinstance(value, (BYTES_TYPE, UNICODE_TYPE)): self.write_blockdata(value) else: diff --git a/javaobj/v1/transformers.py b/javaobj/v1/transformers.py index 7e80f98..c581125 100644 --- a/javaobj/v1/transformers.py +++ b/javaobj/v1/transformers.py @@ -5,12 +5,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/javaobj/v1/unmarshaller.py b/javaobj/v1/unmarshaller.py index 0317e68..c3c7709 100644 --- a/javaobj/v1/unmarshaller.py +++ b/javaobj/v1/unmarshaller.py @@ -13,12 +13,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -72,7 +72,7 @@ __all__ = ("JavaObjectUnmarshaller",) # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v2/__init__.py b/javaobj/v2/__init__.py index 097d54b..e9745ea 100644 --- a/javaobj/v2/__init__.py +++ b/javaobj/v2/__init__.py @@ -15,12 +15,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v2/api.py b/javaobj/v2/api.py index cfcf462..8d9cd0d 100644 --- a/javaobj/v2/api.py +++ b/javaobj/v2/api.py @@ -4,12 +4,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,16 +26,20 @@ from __future__ import absolute_import -from typing import Optional +from typing import List, Optional -from .beans import JavaClassDesc, JavaInstance # pylint:disable=W0611 -from .stream import DataStreamReader # pylint:disable=W0611 from ..constants import TypeCode # pylint:disable=W0611 +from .beans import ( # pylint:disable=W0611 + JavaClassDesc, + JavaInstance, + ParsedJavaContent, +) +from .stream import DataStreamReader # pylint:disable=W0611 # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format @@ -44,6 +48,32 @@ # ------------------------------------------------------------------------------ +class IJavaStreamParser: + """ + API of the Java stream parser + """ + + def run(self): + # type: () -> List[ParsedJavaContent] + """ + Parses the input stream + """ + raise NotImplementedError + + def dump(self, content): + # type: (List[ParsedJavaContent]) -> str + """ + Dumps to a string the given objects + """ + raise NotImplementedError + + def _read_content(self, type_code, block_data, class_desc=None): + # type: (int, bool, Optional[JavaClassDesc]) -> ParsedJavaContent + """ + Parses the next content. Use with care (use only in a transformer) + """ + + class ObjectTransformer(object): # pylint:disable=R0205 """ Representation of an object transformer @@ -84,7 +114,7 @@ def load_array( def load_custom_writeObject( self, parser, reader, name ): # pylint:disable=W0613,R0201 - # type: (JavaStreamParser, DataStreamReader, str) -> Optional[JavaClassDesc] + # type: (IJavaStreamParser, DataStreamReader, str) -> Optional[JavaClassDesc] """ Reads content stored from a custom writeObject. diff --git a/javaobj/v2/beans.py b/javaobj/v2/beans.py index b888a64..0b81f16 100644 --- a/javaobj/v2/beans.py +++ b/javaobj/v2/beans.py @@ -4,12 +4,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,18 +26,18 @@ from __future__ import absolute_import +import logging from enum import IntEnum from typing import Any, Dict, List, Optional, Set -import logging from ..constants import ClassDescFlags, TypeCode -from ..modifiedutf8 import decode_modified_utf8, byte_to_int +from ..modifiedutf8 import byte_to_int, decode_modified_utf8 from ..utils import UNICODE_TYPE # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v2/core.py b/javaobj/v2/core.py index adb140f..8e018a6 100644 --- a/javaobj/v2/core.py +++ b/javaobj/v2/core.py @@ -5,12 +5,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -27,51 +27,50 @@ from __future__ import absolute_import -from typing import ( +import logging +import os +from typing import ( # pylint:disable=W0611 + IO, Any, Callable, Dict, - IO, List, Optional, -) # pylint:disable=W0611 -import logging -import os +) +from ..constants import ( + PRIMITIVE_TYPES, + StreamConstants, + TerminalCode, + TypeCode, +) +from ..modifiedutf8 import ( # pylint:disable=W0611 # noqa: F401 + decode_modified_utf8, +) from . import api # pylint:disable=W0611 from .beans import ( - ParsedJavaContent, BlockData, - JavaClassDesc, - JavaClass, + ClassDataType, + ClassDescType, + ExceptionRead, + ExceptionState, + FieldType, JavaArray, + JavaClass, + JavaClassDesc, JavaEnum, JavaField, JavaInstance, JavaString, - ExceptionState, - ExceptionRead, - ClassDescType, - FieldType, - ClassDataType, + ParsedJavaContent, ) from .stream import DataStreamReader from .transformers import DefaultObjectTransformer -from ..constants import ( - StreamConstants, - TerminalCode, - TypeCode, - PRIMITIVE_TYPES, -) - -from ..modifiedutf8 import ( - decode_modified_utf8, -) # pylint:disable=W0611 # noqa: F401 # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format @@ -80,7 +79,7 @@ # ------------------------------------------------------------------------------ -class JavaStreamParser: +class JavaStreamParser(api.IJavaStreamParser): """ Parses a Java stream """ diff --git a/javaobj/v2/main.py b/javaobj/v2/main.py index e3ef18d..24b51b0 100644 --- a/javaobj/v2/main.py +++ b/javaobj/v2/main.py @@ -5,7 +5,7 @@ from __future__ import absolute_import -from typing import Any, IO # pylint:disable=W0611 +from typing import IO, Any # pylint:disable=W0611 try: # Python 2 @@ -14,15 +14,15 @@ # Python 3+ from io import BytesIO +from ..utils import java_data_fd from .api import ObjectTransformer # pylint:disable=W0611 from .core import JavaStreamParser from .transformers import DefaultObjectTransformer, NumpyArrayTransformer -from ..utils import java_data_fd # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v2/stream.py b/javaobj/v2/stream.py index 1e5ff7a..7cb8a9f 100644 --- a/javaobj/v2/stream.py +++ b/javaobj/v2/stream.py @@ -4,12 +4,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,16 +26,16 @@ from __future__ import absolute_import -from typing import Any, IO, Tuple # pylint:disable=W0611 import struct +from typing import IO, Any, Tuple # pylint:disable=W0611 from ..modifiedutf8 import decode_modified_utf8 -from ..utils import unicode_char, UNICODE_TYPE # pylint:disable=W0611 +from ..utils import UNICODE_TYPE, unicode_char # pylint:disable=W0611 # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format diff --git a/javaobj/v2/transformers.py b/javaobj/v2/transformers.py index 8d5efe0..087eea9 100644 --- a/javaobj/v2/transformers.py +++ b/javaobj/v2/transformers.py @@ -4,12 +4,12 @@ :authors: Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,30 +25,30 @@ """ # Standard library -from typing import List, Optional, Tuple import functools +from typing import List, Optional, Tuple # Numpy (optional) try: import numpy except ImportError: - numpy = None - + numpy = None # type: ignore # Javaobj -from .api import ObjectTransformer -from .beans import ( - JavaInstance, - JavaClassDesc, - BlockData, -) # pylint:disable=W0611 from ..constants import TerminalCode, TypeCode -from ..utils import to_bytes, log_error, log_debug, read_struct, read_string +from ..utils import log_debug, log_error, read_string, read_struct, to_bytes +from .api import IJavaStreamParser, ObjectTransformer +from .beans import ( # pylint:disable=W0611 + BlockData, + JavaClassDesc, + JavaInstance, +) +from .stream import DataStreamReader # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format @@ -183,7 +183,7 @@ class JavaLinkedHashMap(JavaMap): HANDLED_CLASSES = ("java.util.LinkedHashMap",) def load_from_blockdata(self, parser, reader, indent=0): - # type: (JavaStreamParser, DataStreamReader, int) -> bool + # type: (IJavaStreamParser, DataStreamReader, int) -> bool """ Loads the content of the map, written with a custom implementation """ diff --git a/setup.py b/setup.py index cda54e3..8a2318b 100644 --- a/setup.py +++ b/setup.py @@ -7,12 +7,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ # ------------------------------------------------------------------------------ # Module version -__version_info__ = (0, 4, 3) +__version_info__ = (0, 4, 4) __version__ = ".".join(str(x) for x in __version_info__) # Documentation strings format @@ -87,6 +87,10 @@ def read(fname): "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Software Development :: Libraries :: Python Modules", ], ) diff --git a/tests/java/src/test/java/OneTest.java b/tests/java/src/test/java/OneTest.java index 09c16aa..7ffb10a 100644 --- a/tests/java/src/test/java/OneTest.java +++ b/tests/java/src/test/java/OneTest.java @@ -244,6 +244,27 @@ public void testCharArray() throws IOException { oos.close(); } + @Test + public void test2DArray() throws IOException { + int[][] array = new int[][] { + new int[] {1, 2, 3}, + new int[] {4, 5, 6}, + }; + oos.writeObject(array); + oos.close(); + } + + @Test + public void testClassArray() throws IOException { + Class>[] array = new Class>[] { + Integer.class, + ObjectOutputStream.class, + Exception.class, + }; + oos.writeObject(array); + oos.close(); + } + @Test public void testJapan() throws IOException { String stateOfJapan = "日本国"; diff --git a/tests/test2DArray.ser b/tests/test2DArray.ser new file mode 100644 index 0000000..d0f58dc Binary files /dev/null and b/tests/test2DArray.ser differ diff --git a/tests/testClassArray.ser b/tests/testClassArray.ser new file mode 100644 index 0000000..e5501ae Binary files /dev/null and b/tests/testClassArray.ser differ diff --git a/tests/tests.py b/tests/test_v1.py similarity index 97% rename from tests/tests.py rename to tests/test_v1.py index 5de4e1b..162b2db 100644 --- a/tests/tests.py +++ b/tests/test_v1.py @@ -8,12 +8,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -359,6 +359,17 @@ def test_char_array(self): ) self._try_marshalling(jobj, pobj) + def test_2d_array(self): + """ + Tests the handling of a 2D array + """ + jobj = self.read_file("test2DArray.ser") + pobj = javaobj.loads(jobj) + _logger.debug(pobj) + self.assertEqual( + pobj, [[1, 2, 3], [4, 5, 6],], + ) + def test_enums(self): """ Tests the handling of "enum" types diff --git a/tests/tests_v2.py b/tests/test_v2.py similarity index 96% rename from tests/tests_v2.py rename to tests/test_v2.py index afdcb8c..301db9c 100644 --- a/tests/tests_v2.py +++ b/tests/test_v2.py @@ -8,12 +8,12 @@ :authors: Volodymyr Buell, Thomas Calmant :license: Apache License 2.0 -:version: 0.4.3 +:version: 0.4.4 :status: Alpha .. - Copyright 2021 Thomas Calmant + Copyright 2024 Thomas Calmant Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -34,19 +34,19 @@ # Standard library import logging import os +import struct import subprocess import sys import unittest -import struct - from io import BytesIO # Prepare Python path to import javaobj sys.path.insert(0, os.path.abspath(os.path.dirname(os.getcwd()))) +import javaobj.v2 as javaobj + # Local from javaobj.utils import bytes_char, java_data_fd -import javaobj.v2 as javaobj # ------------------------------------------------------------------------------ @@ -57,8 +57,6 @@ # ------------------------------------------------------------------------------ -# ------------------------------------------------------------------------------ - # Custom writeObject parsing classes class CustomWriterInstance(javaobj.beans.JavaInstance): def __init__(self): @@ -455,6 +453,28 @@ def test_char_array(self): ], ) + def test_2d_array(self): + """ + Tests the handling of a 2D array + """ + jobj = self.read_file("test2DArray.ser") + pobj = javaobj.loads(jobj) + _logger.debug(pobj) + self.assertEqual( + pobj, [[1, 2, 3], [4, 5, 6],], + ) + + def test_class_array(self): + """ + Tests the handling of an array of Class objects + """ + jobj = self.read_file("testClassArray.ser") + pobj = javaobj.loads(jobj) + _logger.debug(pobj) + self.assertEqual(pobj[0].name, "java.lang.Integer") + self.assertEqual(pobj[1].name, "java.io.ObjectOutputStream") + self.assertEqual(pobj[2].name, "java.lang.Exception") + def test_enums(self): """ Tests the handling of "enum" types @@ -599,7 +619,8 @@ def test_writeObject(self): self.assertEqual(isinstance(pobj, CustomWriterInstance), True) self.assertEqual( - isinstance(pobj.field_data["custom_obj"], RandomChildInstance), True + isinstance(pobj.field_data["custom_obj"], RandomChildInstance), + True, ) parent_data = pobj.field_data