From df4bd79235143248236aa4566873fa82e3b1b611 Mon Sep 17 00:00:00 2001 From: thibault Date: Mon, 17 Apr 2023 02:48:55 -0400 Subject: [PATCH] Manully merge #28 (with tests), move to pytest --- doc/source/conf.py | 6 +- doc/source/org-doc.rst | 101 ++++++++++----------- hpp2plantuml.org | 147 +++++++++++++++---------------- setup.cfg | 2 +- setup.py | 8 +- src/hpp2plantuml/__init__.py | 4 +- src/hpp2plantuml/hpp2plantuml.py | 16 ++-- tests/simple_classes.puml | 22 ++--- tests/simple_classes_nodep.puml | 20 ++--- tests/test_hpp2plantuml.py | 73 +++++++-------- 10 files changed, 186 insertions(+), 213 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 9a8faac..36c55f0 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -79,9 +79,9 @@ # built documents. # # The short X.Y version. -version = u'v' + u'0.8.3' +version = u'v' + u'0.8.4' # The full version, including alpha/beta/rc tags. -release = u'v' + u'0.8.3' +release = u'v' + u'0.8.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -155,7 +155,7 @@ # The name for this set of Sphinx documents. # " v documentation" by default. # -# html_title = u'hpp2plantuml ' + u'v' + u'0.8.3' +# html_title = u'hpp2plantuml ' + u'v' + u'0.8.4' # A shorter title for the navigation bar. Default is the same as html_title. # diff --git a/doc/source/org-doc.rst b/doc/source/org-doc.rst index 4d727d9..1358dbd 100644 --- a/doc/source/org-doc.rst +++ b/doc/source/org-doc.rst @@ -13,7 +13,7 @@ The current version of the code is: :: :name: hpp2plantuml-version - 0.8.3 + 0.8.4 The source code can be found on GitHub: @@ -123,7 +123,7 @@ block (returning either imports or a dependency list used in `sec-package-setup- import CppHeaderParser import jinja2 -The tests rely on the `nosetest `_ framework and the package documentation is built +The tests rely on the `pytest `_ framework and the package documentation is built with `Sphinx `_. .. _sec-module: @@ -648,8 +648,8 @@ to the `sec-module-class-member`_. member_scope : str Scope property to member variable """ - assert(isinstance(class_variable, - CppHeaderParser.CppHeaderParser.CppVariable)) + assert isinstance(class_variable, + CppHeaderParser.CppHeaderParser.CppVariable) super().__init__(class_variable, member_scope) @@ -709,8 +709,8 @@ implemented in the future. Scope of the member method """ - assert(isinstance(class_method, - CppHeaderParser.CppHeaderParser.CppMethod)) + assert isinstance(class_method, + CppHeaderParser.CppHeaderParser.CppMethod) super().__init__(class_method, member_scope) @@ -741,7 +741,7 @@ implemented in the future. The method name (prefixed with the ``abstract`` keyword when appropriate) and signature """ - assert(not self._static or not self._abstract) + assert not self._static or not self._abstract method_str = ('{abstract} ' if self._abstract else '') + \ self._name + '(' + \ @@ -943,7 +943,9 @@ strings and the text representation of a connection link is obtained from the str Class name with appropriate prefix for use with link rendering """ - return get_namespace_link_name(class_namespace) + '.' + class_name + if class_namespace: + return get_namespace_link_name(class_namespace) + '.' + class_name + return class_name def render(self): """Render class relationship to string @@ -2054,7 +2056,7 @@ to parse input arguments. The function passes the command line arguments to the required=False, default=None, metavar='JINJA-FILE', help='path to jinja2 template file') parser.add_argument('--version', action='version', - version='%(prog)s ' + '0.8.3') + version='%(prog)s ' + '0.8.4') args = parser.parse_args() if len(args.input_files) > 0: CreatePlantUMLFile(args.input_files, args.output_file, @@ -2186,7 +2188,7 @@ documentation for more details. Tests ----- -Testing is performed using the `nose `_ framework. The tests are defined in the +Testing is performed using the `pytest `_ framework. The tests are defined in the ``test_hpp2plantuml.py`` file located in the test folder. They can be run with the ``python setup.py test`` command. @@ -2211,7 +2213,7 @@ Following is the test setup code. import io import sys import re - import nose.tools as nt + import pytest import CppHeaderParser import hpp2plantuml @@ -2224,7 +2226,7 @@ Following is the test setup code. return CppHeaderParser.CppHeader(input_str, argType='string') - @nt.nottest + @pytest.mark.skip(reason='not a test') def fix_test_list_def(test_list): test_list_out = [] for test_entry in test_list: @@ -2258,8 +2260,8 @@ sorting keys. c_type = "container_type" c_name = "container_name" c_obj = hpp2plantuml.hpp2plantuml.Container(c_type, c_name) - nt.assert_equal(c_obj.name, c_name) - nt.assert_equal(c_obj.render(), 'container_type container_name {\n}\n') + assert c_obj.name == c_name + assert c_obj.render() == 'container_type container_name {\n}\n' def test_comparison_keys(self): c_list = [ @@ -2275,8 +2277,7 @@ sorting keys. c_obj_list.sort(key=lambda obj: obj.comparison_keys()) for i in range(len(c_list)): - nt.assert_equal(c_obj_list[i].name, - c_list[ref_sort_idx[i]][1]) + assert c_obj_list[i].name == c_list[ref_sort_idx[i]][1] Class ^^^^^ @@ -2324,9 +2325,7 @@ the representation of variables. class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) obj_m = obj_c._member_list[0] - nt.assert_equal(output_ref_str, obj_m.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_m.render() Class method :::::::::::: @@ -2369,9 +2368,7 @@ supported by PlantUML. class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) obj_m = obj_c._member_list[0] - nt.assert_equal(output_ref_str, obj_m.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_m.render() Class ::::: @@ -2413,9 +2410,7 @@ TableĀ `tbl-unittest-class`_. It includes templates and abstract classes. input_str.replace('\n', ' ')) class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) - nt.assert_equal(output_ref_str, obj_c.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_c.render() Enum ^^^^ @@ -2452,9 +2447,7 @@ TableĀ `tbl-unittest-enum`_. input_str.replace('\n', ' ')) enum_input = p.enums[0] obj_c = hpp2plantuml.hpp2plantuml.Enum(enum_input) - nt.assert_equal(output_ref_str, obj_c.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_c.render() Links ^^^^^ @@ -2504,9 +2497,7 @@ relationships (with and without count). obj_l = obj_d._aggregation_list[0] elif len(obj_d._dependency_list) > 0: obj_l = obj_d._dependency_list[0] - nt.assert_equal(output_ref_str, obj_l.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_l.render() Full system test ~~~~~~~~~~~~~~~~ @@ -3056,7 +3047,7 @@ The system test validates the following: class TestFullDiagram(): - def __init__(self): + def setup_class(self): self._input_files = ['simple_classes_1_2.hpp', 'simple_classes_3.hpp'] self._input_files_w = ['simple_classes_*.hpp', 'simple_classes_3.hpp'] self._diag_saved_ref = '' @@ -3084,7 +3075,7 @@ The system test validates the following: saved_ref = self._diag_saved_ref else: saved_ref = self._diag_saved_ref_nodep - nt.assert_equal(saved_ref, diag_render_ref) + assert saved_ref == diag_render_ref # # Validate equivalent inputs @@ -3096,14 +3087,14 @@ The system test validates the following: # Create from file list diag_c = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_c.create_from_file_list(file_list_c) - nt.assert_equal(diag_render_ref, diag_c.render()) + assert diag_render_ref == diag_c.render() # Add from file list diag_c_add = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_c_add.add_from_file_list(file_list_c) diag_c_add.build_relationship_lists() diag_c_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_c_add.render()) + assert diag_render_ref == diag_c_add.render() # Create from first file, add from rest of the list diag_c_file = hpp2plantuml.Diagram(flag_dep=flag_dep) @@ -3112,7 +3103,7 @@ The system test validates the following: diag_c_file.add_from_file(file_c) diag_c_file.build_relationship_lists() diag_c_file.sort_elements() - nt.assert_equal(diag_render_ref, diag_c_file.render()) + assert diag_render_ref == diag_c_file.render() # String inputs input_str_list = [] @@ -3123,23 +3114,23 @@ The system test validates the following: # Create from string list diag_str_list = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str_list.create_from_string_list(input_str_list) - nt.assert_equal(diag_render_ref, diag_str_list.render()) + assert diag_render_ref == diag_str_list.render() # Add from string list diag_str_list_add = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str_list_add.add_from_string_list(input_str_list) diag_str_list_add.build_relationship_lists() diag_str_list_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_str_list_add.render()) + assert diag_render_ref == diag_str_list_add.render() # Create from string diag_str = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str.create_from_string('\n'.join(input_str_list)) - nt.assert_equal(diag_render_ref, diag_str.render()) + assert diag_render_ref == diag_str.render() # Reset and parse diag_str.clear() diag_str.create_from_string('\n'.join(input_str_list)) - nt.assert_equal(diag_render_ref, diag_str.render()) + assert diag_render_ref == diag_str.render() # Manually build object diag_manual_add = hpp2plantuml.Diagram(flag_dep=flag_dep) @@ -3151,7 +3142,7 @@ The system test validates the following: diag_manual_add.add_from_string(string_c) diag_manual_add.build_relationship_lists() diag_manual_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_manual_add.render()) + assert diag_render_ref == diag_manual_add.render() def test_main_function(self): #self._test_main_function_helper(False) @@ -3174,7 +3165,7 @@ The system test validates the following: saved_ref = self._diag_saved_ref else: saved_ref = self._diag_saved_ref_nodep - nt.assert_equal(saved_ref, output_str) + assert saved_ref == output_str # Output to file output_fname = 'output.puml' @@ -3188,10 +3179,10 @@ The system test validates the following: output_fcontent = fid.read() if template is None: # Default template check - nt.assert_equal(saved_ref, output_fcontent) + assert saved_ref == output_fcontent else: # Check that all lines of reference are in the output - ref_re = re.search('(@startuml)\s*(.*)', saved_ref, re.DOTALL) + ref_re = re.search(r'(@startuml)\s*(.*)', saved_ref, re.DOTALL) assert ref_re # Build regular expression: allow arbitrary text between # @startuml and the rest of the string @@ -3201,7 +3192,7 @@ The system test validates the following: '.*', # preamble re.escape(ref_groups[1])]), # main output re.DOTALL) - nt.assert_true(match_re.search(output_fcontent)) + assert match_re.search(output_fcontent) os.unlink(output_fname) Packaging @@ -3346,13 +3337,13 @@ obtained using the source block described `sec-org-el-version`_. __title__ = "hpp2plantuml" __description__ = "Convert C++ header files to PlantUML" - __version__ = '0.8.3' + __version__ = '0.8.4' __uri__ = "https://github.com/thibaultmarin/hpp2plantuml" __doc__ = __description__ + " <" + __uri__ + ">" __author__ = "Thibault Marin" __email__ = "thibault.marin@gmx.com" __license__ = "MIT" - __copyright__ = "Copyright (c) 2021 Thibault Marin" + __copyright__ = "Copyright (c) 2023 Thibault Marin" from .hpp2plantuml import CreatePlantUMLFile, Diagram @@ -3378,7 +3369,7 @@ documentation files. In practice, the documentation is built using a `sec-packa universal = 1 [metadata] - license_file = LICENSE + license_files = LICENSE [build_sphinx] source-dir = doc/source @@ -3406,7 +3397,7 @@ options. Most of it is taken from `this post v documentation" by default. # - # html_title = u'hpp2plantuml ' + u'v' + u'0.8.3' + # html_title = u'hpp2plantuml ' + u'v' + u'0.8.4' # A shorter title for the navigation bar. Default is the same as html_title. # diff --git a/hpp2plantuml.org b/hpp2plantuml.org index 1b00dfa..29190e4 100644 --- a/hpp2plantuml.org +++ b/hpp2plantuml.org @@ -16,7 +16,7 @@ this single org-file. The current version of the code is: #+NAME: hpp2plantuml-version -: 0.8.3 +: 0.8.4 The source code can be found on GitHub: https://github.com/thibaultmarin/hpp2plantuml. @@ -114,7 +114,7 @@ import glob <> #+END_SRC -The tests rely on the [[http://nose.readthedocs.io/en/latest/][nosetest]] framework and the package documentation is built +The tests rely on the [[https://docs.pytest.org/en/7.3.x/][pytest]] framework and the package documentation is built with [[http://sphinx-doc.org][Sphinx]]. @@ -633,8 +633,8 @@ class ClassVariable(ClassMember): member_scope : str Scope property to member variable """ - assert(isinstance(class_variable, - CppHeaderParser.CppHeaderParser.CppVariable)) + assert isinstance(class_variable, + CppHeaderParser.CppHeaderParser.CppVariable) super().__init__(class_variable, member_scope) @@ -695,8 +695,8 @@ class ClassMethod(ClassMember): Scope of the member method """ - assert(isinstance(class_method, - CppHeaderParser.CppHeaderParser.CppMethod)) + assert isinstance(class_method, + CppHeaderParser.CppHeaderParser.CppMethod) super().__init__(class_method, member_scope) @@ -727,7 +727,7 @@ class ClassMethod(ClassMember): The method name (prefixed with the ``abstract`` keyword when appropriate) and signature """ - assert(not self._static or not self._abstract) + assert not self._static or not self._abstract method_str = ('{abstract} ' if self._abstract else '') + \ self._name + '(' + \ @@ -930,7 +930,9 @@ class ClassRelationship(object): str Class name with appropriate prefix for use with link rendering """ - return get_namespace_link_name(class_namespace) + '.' + class_name + if class_namespace: + return get_namespace_link_name(class_namespace) + '.' + class_name + return class_name def render(self): """Render class relationship to string @@ -2159,7 +2161,7 @@ documentation for more details. :header-args:python+: :tangle tests/test_hpp2plantuml.py :END: -Testing is performed using the [[http://nose.readthedocs.io/en/latest/][nose]] framework. The tests are defined in the +Testing is performed using the [[https://docs.pytest.org/en/7.3.x/][pytest]] framework. The tests are defined in the =test_hpp2plantuml.py= file located in the test folder. They can be run with the =python setup.py test= command. @@ -2183,7 +2185,7 @@ import os import io import sys import re -import nose.tools as nt +import pytest import CppHeaderParser import hpp2plantuml @@ -2196,7 +2198,7 @@ def get_parsed_element(input_str): return CppHeaderParser.CppHeader(input_str, argType='string') -@nt.nottest +@pytest.mark.skip(reason='not a test') def fix_test_list_def(test_list): test_list_out = [] for test_entry in test_list: @@ -2228,8 +2230,8 @@ class TestContainer: c_type = "container_type" c_name = "container_name" c_obj = hpp2plantuml.hpp2plantuml.Container(c_type, c_name) - nt.assert_equal(c_obj.name, c_name) - nt.assert_equal(c_obj.render(), 'container_type container_name {\n}\n') + assert c_obj.name == c_name + assert c_obj.render() == 'container_type container_name {\n}\n' def test_comparison_keys(self): c_list = [ @@ -2245,8 +2247,7 @@ class TestContainer: c_obj_list.sort(key=lambda obj: obj.comparison_keys()) for i in range(len(c_list)): - nt.assert_equal(c_obj_list[i].name, - c_list[ref_sort_idx[i]][1]) + assert c_obj_list[i].name == c_list[ref_sort_idx[i]][1] #+END_SRC @@ -2289,9 +2290,7 @@ class TestClassVariable: class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) obj_m = obj_c._member_list[0] - nt.assert_equal(output_ref_str, obj_m.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_m.render() #+END_SRC @@ -2327,9 +2326,7 @@ class TestClassMethod: class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) obj_m = obj_c._member_list[0] - nt.assert_equal(output_ref_str, obj_m.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_m.render() #+END_SRC @@ -2363,9 +2360,7 @@ class TestClass: input_str.replace('\n', ' ')) class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) - nt.assert_equal(output_ref_str, obj_c.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_c.render() #+END_SRC @@ -2397,9 +2392,7 @@ class TestEnum: input_str.replace('\n', ' ')) enum_input = p.enums[0] obj_c = hpp2plantuml.hpp2plantuml.Enum(enum_input) - nt.assert_equal(output_ref_str, obj_c.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_c.render() #+END_SRC @@ -2414,14 +2407,14 @@ relationships (with and without count). #+CAPTION: List of test segments and corresponding PlantUML strings. | C++ | plantuml | |------------------------------------------------------+---------------------| -| "class A{};\nclass B : A{};" | ".A <@-- .B\n" | -| "class A{};\nclass B : public A{};" | ".A <@-- .B\n" | -| "class B{};\nclass A{B obj;};" | ".A *-- .B\n" | -| "class B{};\nclass A{B* obj;};" | ".A o-- .B\n" | -| "class B{};\nclass A{B * obj_ptr; B* ptr;};" | ".A \"2\" o-- .B\n" | -| "class A{};\nclass B{void Method(A* obj);};" | ".A <.. .B\n" | +| "class A{};\nclass B : A{};" | "A <@-- B\n" | +| "class A{};\nclass B : public A{};" | "A <@-- B\n" | +| "class B{};\nclass A{B obj;};" | "A *-- B\n" | +| "class B{};\nclass A{B* obj;};" | "A o-- B\n" | +| "class B{};\nclass A{B * obj_ptr; B* ptr;};" | "A \"2\" o-- B\n" | +| "class A{};\nclass B{void Method(A* obj);};" | "A <.. B\n" | | "namespace T {class A{}; class B: A{};};" | "T.A <@-- T.B\n" | -| "namespace T {\nclass A{};};\nclass B{T::A* _obj;};" | ".B o-- T.A\n" | +| "namespace T {\nclass A{};};\nclass B{T::A* _obj;};" | "B o-- T.A\n" | #+NAME: test-unit-link @@ -2439,9 +2432,7 @@ class TestLink: obj_l = obj_d._aggregation_list[0] elif len(obj_d._dependency_list) > 0: obj_l = obj_d._dependency_list[0] - nt.assert_equal(output_ref_str, obj_l.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_l.render() #+END_SRC @@ -2706,13 +2697,13 @@ namespace Interface { /' Inheritance relationships '/ -first_ns.second_ns.A <|-- .Class03 +first_ns.second_ns.A <|-- Class03 -.Class01 <|-- .Class02 +Class01 <|-- Class02 -.Class02 <|-- first_ns.second_ns.A +Class02 <|-- first_ns.second_ns.A Interface.Class04 <|-- Interface.Class04_derived @@ -2726,16 +2717,16 @@ Interface.Class04_derived <|-- Interface.NestedNamespace.Class04_ns /' Aggregation relationships '/ -.Class03 "2" o-- .Class01 +Class03 "2" o-- Class01 -.Class03 *-- .Class02 +Class03 *-- Class02 -Interface.Class04 o-- .Class01 +Interface.Class04 o-- Class01 -Interface.Class04 *-- .Enum01 +Interface.Class04 *-- Enum01 Interface.NestedNamespace.Class04_ns *-- Interface.Enum @@ -2750,7 +2741,7 @@ Interface.NestedNamespace.Class04_ns *-- Interface.Struct /' Dependency relationships '/ -Interface.Class04 <.. .Class03 +Interface.Class04 <.. Class03 @@ -2759,13 +2750,13 @@ Interface.Class04 <.. .Class03 /' Nested objects '/ -.Class02 +-- .Class02::ClassNested +Class02 +-- Class02::ClassNested -.anon_union_1 +-- .anon_union_1::anon_struct_1 +anon_union_1 +-- anon_union_1::anon_struct_1 -.anon_union_1 +-- .anon_union_1::anon_struct_2 +anon_union_1 +-- anon_union_1::anon_struct_2 @@ -2898,13 +2889,13 @@ namespace Interface { /' Inheritance relationships '/ -first_ns.second_ns.A <|-- .Class03 +first_ns.second_ns.A <|-- Class03 -.Class01 <|-- .Class02 +Class01 <|-- Class02 -.Class02 <|-- first_ns.second_ns.A +Class02 <|-- first_ns.second_ns.A Interface.Class04 <|-- Interface.Class04_derived @@ -2918,16 +2909,16 @@ Interface.Class04_derived <|-- Interface.NestedNamespace.Class04_ns /' Aggregation relationships '/ -.Class03 "2" o-- .Class01 +Class03 "2" o-- Class01 -.Class03 *-- .Class02 +Class03 *-- Class02 -Interface.Class04 o-- .Class01 +Interface.Class04 o-- Class01 -Interface.Class04 *-- .Enum01 +Interface.Class04 *-- Enum01 Interface.NestedNamespace.Class04_ns *-- Interface.Enum @@ -2942,13 +2933,13 @@ Interface.NestedNamespace.Class04_ns *-- Interface.Struct /' Nested objects '/ -.Class02 +-- .Class02::ClassNested +Class02 +-- Class02::ClassNested -.anon_union_1 +-- .anon_union_1::anon_struct_1 +anon_union_1 +-- anon_union_1::anon_struct_1 -.anon_union_1 +-- .anon_union_1::anon_struct_2 +anon_union_1 +-- anon_union_1::anon_struct_2 @@ -2986,7 +2977,7 @@ skinparam handwritten true class TestFullDiagram(): - def __init__(self): + def setup_class(self): self._input_files = ['simple_classes_1_2.hpp', 'simple_classes_3.hpp'] self._input_files_w = ['simple_classes_*.hpp', 'simple_classes_3.hpp'] self._diag_saved_ref = '' @@ -3014,7 +3005,7 @@ class TestFullDiagram(): saved_ref = self._diag_saved_ref else: saved_ref = self._diag_saved_ref_nodep - nt.assert_equal(saved_ref, diag_render_ref) + assert saved_ref == diag_render_ref # # Validate equivalent inputs @@ -3026,14 +3017,14 @@ class TestFullDiagram(): # Create from file list diag_c = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_c.create_from_file_list(file_list_c) - nt.assert_equal(diag_render_ref, diag_c.render()) + assert diag_render_ref == diag_c.render() # Add from file list diag_c_add = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_c_add.add_from_file_list(file_list_c) diag_c_add.build_relationship_lists() diag_c_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_c_add.render()) + assert diag_render_ref == diag_c_add.render() # Create from first file, add from rest of the list diag_c_file = hpp2plantuml.Diagram(flag_dep=flag_dep) @@ -3042,7 +3033,7 @@ class TestFullDiagram(): diag_c_file.add_from_file(file_c) diag_c_file.build_relationship_lists() diag_c_file.sort_elements() - nt.assert_equal(diag_render_ref, diag_c_file.render()) + assert diag_render_ref == diag_c_file.render() # String inputs input_str_list = [] @@ -3053,23 +3044,23 @@ class TestFullDiagram(): # Create from string list diag_str_list = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str_list.create_from_string_list(input_str_list) - nt.assert_equal(diag_render_ref, diag_str_list.render()) + assert diag_render_ref == diag_str_list.render() # Add from string list diag_str_list_add = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str_list_add.add_from_string_list(input_str_list) diag_str_list_add.build_relationship_lists() diag_str_list_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_str_list_add.render()) + assert diag_render_ref == diag_str_list_add.render() # Create from string diag_str = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str.create_from_string('\n'.join(input_str_list)) - nt.assert_equal(diag_render_ref, diag_str.render()) + assert diag_render_ref == diag_str.render() # Reset and parse diag_str.clear() diag_str.create_from_string('\n'.join(input_str_list)) - nt.assert_equal(diag_render_ref, diag_str.render()) + assert diag_render_ref == diag_str.render() # Manually build object diag_manual_add = hpp2plantuml.Diagram(flag_dep=flag_dep) @@ -3081,7 +3072,7 @@ class TestFullDiagram(): diag_manual_add.add_from_string(string_c) diag_manual_add.build_relationship_lists() diag_manual_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_manual_add.render()) + assert diag_render_ref == diag_manual_add.render() def test_main_function(self): #self._test_main_function_helper(False) @@ -3104,7 +3095,7 @@ class TestFullDiagram(): saved_ref = self._diag_saved_ref else: saved_ref = self._diag_saved_ref_nodep - nt.assert_equal(saved_ref, output_str) + assert saved_ref == output_str # Output to file output_fname = 'output.puml' @@ -3118,10 +3109,10 @@ class TestFullDiagram(): output_fcontent = fid.read() if template is None: # Default template check - nt.assert_equal(saved_ref, output_fcontent) + assert saved_ref == output_fcontent else: # Check that all lines of reference are in the output - ref_re = re.search('(@startuml)\s*(.*)', saved_ref, re.DOTALL) + ref_re = re.search(r'(@startuml)\s*(.*)', saved_ref, re.DOTALL) assert ref_re # Build regular expression: allow arbitrary text between # @startuml and the rest of the string @@ -3131,7 +3122,7 @@ class TestFullDiagram(): '.*', # preamble re.escape(ref_groups[1])]), # main output re.DOTALL) - nt.assert_true(match_re.search(output_fcontent)) + assert match_re.search(output_fcontent) os.unlink(output_fname) #+END_SRC @@ -3181,7 +3172,7 @@ __doc__ = __description__ + " <" + __uri__ + ">" __author__ = "Thibault Marin" __email__ = "thibault.marin@gmx.com" __license__ = "MIT" -__copyright__ = "Copyright (c) 2021 Thibault Marin" +__copyright__ = "Copyright (c) 2023 Thibault Marin" from .hpp2plantuml import CreatePlantUMLFile, Diagram @@ -3208,7 +3199,7 @@ command]] for =setup.py= run using ~python setup.py sphinx~. universal = 1 [metadata] -license_file = LICENSE +license_files = LICENSE [build_sphinx] source-dir = doc/source @@ -3239,7 +3230,7 @@ import sys import re import codecs -from setuptools import setup, find_packages, Command +from setuptools import setup, find_namespace_packages, Command try: import sphinx import sphinx.ext.apidoc @@ -3259,7 +3250,7 @@ The non-boilerplate part of the =setup.py= file defines the package information. ################################################################### NAME = "hpp2plantuml" -PACKAGES = find_packages(where="src") +PACKAGES = find_namespace_packages(where="src") META_PATH = os.path.join("src", NAME, "__init__.py") KEYWORDS = ["class"] CLASSIFIERS = [ @@ -3380,8 +3371,8 @@ if __name__ == "__main__": classifiers=CLASSIFIERS, install_requires=INSTALL_REQUIRES, setup_requires=SETUP_REQUIRES, - test_suite='nose.collector', - tests_require=['nose'], + test_suite='pytest', + tests_require=['pytest'], entry_points={ 'console_scripts': ['hpp2plantuml=hpp2plantuml.hpp2plantuml:main'] }, diff --git a/setup.cfg b/setup.cfg index eaa7d6a..30954ea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ universal = 1 [metadata] -license_file = LICENSE +license_files = LICENSE [build_sphinx] source-dir = doc/source diff --git a/setup.py b/setup.py index 0e70ca5..0e5a46d 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ import re import codecs -from setuptools import setup, find_packages, Command +from setuptools import setup, find_namespace_packages, Command try: import sphinx import sphinx.ext.apidoc @@ -17,7 +17,7 @@ ################################################################### NAME = "hpp2plantuml" -PACKAGES = find_packages(where="src") +PACKAGES = find_namespace_packages(where="src") META_PATH = os.path.join("src", NAME, "__init__.py") KEYWORDS = ["class"] CLASSIFIERS = [ @@ -115,8 +115,8 @@ def run(self): classifiers=CLASSIFIERS, install_requires=INSTALL_REQUIRES, setup_requires=SETUP_REQUIRES, - test_suite='nose.collector', - tests_require=['nose'], + test_suite='pytest', + tests_require=['pytest'], entry_points={ 'console_scripts': ['hpp2plantuml=hpp2plantuml.hpp2plantuml:main'] }, diff --git a/src/hpp2plantuml/__init__.py b/src/hpp2plantuml/__init__.py index 6fec276..7738b0f 100644 --- a/src/hpp2plantuml/__init__.py +++ b/src/hpp2plantuml/__init__.py @@ -106,13 +106,13 @@ __title__ = "hpp2plantuml" __description__ = "Convert C++ header files to PlantUML" -__version__ = '0.8.3' +__version__ = '0.8.4' __uri__ = "https://github.com/thibaultmarin/hpp2plantuml" __doc__ = __description__ + " <" + __uri__ + ">" __author__ = "Thibault Marin" __email__ = "thibault.marin@gmx.com" __license__ = "MIT" -__copyright__ = "Copyright (c) 2021 Thibault Marin" +__copyright__ = "Copyright (c) 2023 Thibault Marin" from .hpp2plantuml import CreatePlantUMLFile, Diagram diff --git a/src/hpp2plantuml/hpp2plantuml.py b/src/hpp2plantuml/hpp2plantuml.py index 92bddb6..e7049c9 100644 --- a/src/hpp2plantuml/hpp2plantuml.py +++ b/src/hpp2plantuml/hpp2plantuml.py @@ -401,8 +401,8 @@ def __init__(self, class_variable, member_scope='private'): member_scope : str Scope property to member variable """ - assert(isinstance(class_variable, - CppHeaderParser.CppHeaderParser.CppVariable)) + assert isinstance(class_variable, + CppHeaderParser.CppHeaderParser.CppVariable) super().__init__(class_variable, member_scope) @@ -445,8 +445,8 @@ def __init__(self, class_method, member_scope): Scope of the member method """ - assert(isinstance(class_method, - CppHeaderParser.CppHeaderParser.CppMethod)) + assert isinstance(class_method, + CppHeaderParser.CppHeaderParser.CppMethod) super().__init__(class_method, member_scope) @@ -477,7 +477,7 @@ def _render_name(self): The method name (prefixed with the ``abstract`` keyword when appropriate) and signature """ - assert(not self._static or not self._abstract) + assert not self._static or not self._abstract method_str = ('{abstract} ' if self._abstract else '') + \ self._name + '(' + \ @@ -641,7 +641,9 @@ def _render_name(self, class_name, class_namespace): str Class name with appropriate prefix for use with link rendering """ - return get_namespace_link_name(class_namespace) + '.' + class_name + if class_namespace: + return get_namespace_link_name(class_namespace) + '.' + class_name + return class_name def render(self): """Render class relationship to string @@ -1493,7 +1495,7 @@ def main(): required=False, default=None, metavar='JINJA-FILE', help='path to jinja2 template file') parser.add_argument('--version', action='version', - version='%(prog)s ' + '0.8.3') + version='%(prog)s ' + '0.8.4') args = parser.parse_args() if len(args.input_files) > 0: CreatePlantUMLFile(args.input_files, args.output_file, diff --git a/tests/simple_classes.puml b/tests/simple_classes.puml index 8af1842..379cbbe 100644 --- a/tests/simple_classes.puml +++ b/tests/simple_classes.puml @@ -121,13 +121,13 @@ namespace Interface { /' Inheritance relationships '/ -first_ns.second_ns.A <|-- .Class03 +first_ns.second_ns.A <|-- Class03 -.Class01 <|-- .Class02 +Class01 <|-- Class02 -.Class02 <|-- first_ns.second_ns.A +Class02 <|-- first_ns.second_ns.A Interface.Class04 <|-- Interface.Class04_derived @@ -141,16 +141,16 @@ Interface.Class04_derived <|-- Interface.NestedNamespace.Class04_ns /' Aggregation relationships '/ -.Class03 "2" o-- .Class01 +Class03 "2" o-- Class01 -.Class03 *-- .Class02 +Class03 *-- Class02 -Interface.Class04 o-- .Class01 +Interface.Class04 o-- Class01 -Interface.Class04 *-- .Enum01 +Interface.Class04 *-- Enum01 Interface.NestedNamespace.Class04_ns *-- Interface.Enum @@ -165,7 +165,7 @@ Interface.NestedNamespace.Class04_ns *-- Interface.Struct /' Dependency relationships '/ -Interface.Class04 <.. .Class03 +Interface.Class04 <.. Class03 @@ -174,13 +174,13 @@ Interface.Class04 <.. .Class03 /' Nested objects '/ -.Class02 +-- .Class02::ClassNested +Class02 +-- Class02::ClassNested -.anon_union_1 +-- .anon_union_1::anon_struct_1 +anon_union_1 +-- anon_union_1::anon_struct_1 -.anon_union_1 +-- .anon_union_1::anon_struct_2 +anon_union_1 +-- anon_union_1::anon_struct_2 diff --git a/tests/simple_classes_nodep.puml b/tests/simple_classes_nodep.puml index fe9f267..3dd477b 100644 --- a/tests/simple_classes_nodep.puml +++ b/tests/simple_classes_nodep.puml @@ -121,13 +121,13 @@ namespace Interface { /' Inheritance relationships '/ -first_ns.second_ns.A <|-- .Class03 +first_ns.second_ns.A <|-- Class03 -.Class01 <|-- .Class02 +Class01 <|-- Class02 -.Class02 <|-- first_ns.second_ns.A +Class02 <|-- first_ns.second_ns.A Interface.Class04 <|-- Interface.Class04_derived @@ -141,16 +141,16 @@ Interface.Class04_derived <|-- Interface.NestedNamespace.Class04_ns /' Aggregation relationships '/ -.Class03 "2" o-- .Class01 +Class03 "2" o-- Class01 -.Class03 *-- .Class02 +Class03 *-- Class02 -Interface.Class04 o-- .Class01 +Interface.Class04 o-- Class01 -Interface.Class04 *-- .Enum01 +Interface.Class04 *-- Enum01 Interface.NestedNamespace.Class04_ns *-- Interface.Enum @@ -165,13 +165,13 @@ Interface.NestedNamespace.Class04_ns *-- Interface.Struct /' Nested objects '/ -.Class02 +-- .Class02::ClassNested +Class02 +-- Class02::ClassNested -.anon_union_1 +-- .anon_union_1::anon_struct_1 +anon_union_1 +-- anon_union_1::anon_struct_1 -.anon_union_1 +-- .anon_union_1::anon_struct_2 +anon_union_1 +-- anon_union_1::anon_struct_2 diff --git a/tests/test_hpp2plantuml.py b/tests/test_hpp2plantuml.py index d9ef61c..1fbb462 100644 --- a/tests/test_hpp2plantuml.py +++ b/tests/test_hpp2plantuml.py @@ -7,7 +7,7 @@ import io import sys import re -import nose.tools as nt +import pytest import CppHeaderParser import hpp2plantuml @@ -20,7 +20,7 @@ def get_parsed_element(input_str): return CppHeaderParser.CppHeader(input_str, argType='string') -@nt.nottest +@pytest.mark.skip(reason='not a test') def fix_test_list_def(test_list): test_list_out = [] for test_entry in test_list: @@ -38,8 +38,8 @@ def test_init(self): c_type = "container_type" c_name = "container_name" c_obj = hpp2plantuml.hpp2plantuml.Container(c_type, c_name) - nt.assert_equal(c_obj.name, c_name) - nt.assert_equal(c_obj.render(), 'container_type container_name {\n}\n') + assert c_obj.name == c_name + assert c_obj.render() == 'container_type container_name {\n}\n' def test_comparison_keys(self): c_list = [ @@ -55,8 +55,7 @@ def test_comparison_keys(self): c_obj_list.sort(key=lambda obj: obj.comparison_keys()) for i in range(len(c_list)): - nt.assert_equal(c_obj_list[i].name, - c_list[ref_sort_idx[i]][1]) + assert c_obj_list[i].name == c_list[ref_sort_idx[i]][1] test_list_classvar=[["""class Test { public: @@ -78,9 +77,7 @@ def test_list_entries(self): class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) obj_m = obj_c._member_list[0] - nt.assert_equal(output_ref_str, obj_m.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_m.render() test_list_classmethod=[["""class Test { public: @@ -106,9 +103,7 @@ def test_list_entries(self): class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) obj_m = obj_c._member_list[0] - nt.assert_equal(output_ref_str, obj_m.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_m.render() test_list_class=[["""class Test { protected: @@ -153,9 +148,7 @@ def test_list_entries(self): input_str.replace('\n', ' ')) class_input = [class_name, p.classes[class_name]] obj_c = hpp2plantuml.hpp2plantuml.Class(class_input) - nt.assert_equal(output_ref_str, obj_c.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_c.render() test_list_enum=[["enum Test { A, B, CD, E };", """enum Test { A @@ -187,26 +180,24 @@ def test_list_entries(self): input_str.replace('\n', ' ')) enum_input = p.enums[0] obj_c = hpp2plantuml.hpp2plantuml.Enum(enum_input) - nt.assert_equal(output_ref_str, obj_c.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_c.render() test_list_link=[["""class A{}; -class B : A{};""", """.A <@-- .B +class B : A{};""", """A <@-- B """], ["""class A{}; -class B : public A{};""", """.A <@-- .B +class B : public A{};""", """A <@-- B """], ["""class B{}; -class A{B obj;};""", """.A *-- .B +class A{B obj;};""", """A *-- B """], ["""class B{}; -class A{B* obj;};""", """.A o-- .B +class A{B* obj;};""", """A o-- B """], ["""class B{}; -class A{B * obj_ptr; B* ptr;};""", """.A \"2\" o-- .B +class A{B * obj_ptr; B* ptr;};""", """A \"2\" o-- B """], ["""class A{}; -class B{void Method(A* obj);};""", """.A <.. .B +class B{void Method(A* obj);};""", """A <.. B """], ["namespace T {class A{}; class B: A{};};", """T.A <@-- T.B """], ["""namespace T { class A{};}; -class B{T::A* _obj;};""", """.B o-- T.A +class B{T::A* _obj;};""", """B o-- T.A """]] class TestLink: def test_list_entries(self): @@ -221,16 +212,14 @@ def test_list_entries(self): obj_l = obj_d._aggregation_list[0] elif len(obj_d._dependency_list) > 0: obj_l = obj_d._dependency_list[0] - nt.assert_equal(output_ref_str, obj_l.render(), - 'Test {0} failed [input: {1}]'.format(test_idx, - input_str)) + assert output_ref_str == obj_l.render() # %% Test overall system class TestFullDiagram(): - def __init__(self): + def setup_class(self): self._input_files = ['simple_classes_1_2.hpp', 'simple_classes_3.hpp'] self._input_files_w = ['simple_classes_*.hpp', 'simple_classes_3.hpp'] self._diag_saved_ref = '' @@ -258,7 +247,7 @@ def _test_full_files_helper(self, flag_dep=False): saved_ref = self._diag_saved_ref else: saved_ref = self._diag_saved_ref_nodep - nt.assert_equal(saved_ref, diag_render_ref) + assert saved_ref == diag_render_ref # # Validate equivalent inputs @@ -270,14 +259,14 @@ def _test_full_files_helper(self, flag_dep=False): # Create from file list diag_c = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_c.create_from_file_list(file_list_c) - nt.assert_equal(diag_render_ref, diag_c.render()) + assert diag_render_ref == diag_c.render() # Add from file list diag_c_add = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_c_add.add_from_file_list(file_list_c) diag_c_add.build_relationship_lists() diag_c_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_c_add.render()) + assert diag_render_ref == diag_c_add.render() # Create from first file, add from rest of the list diag_c_file = hpp2plantuml.Diagram(flag_dep=flag_dep) @@ -286,7 +275,7 @@ def _test_full_files_helper(self, flag_dep=False): diag_c_file.add_from_file(file_c) diag_c_file.build_relationship_lists() diag_c_file.sort_elements() - nt.assert_equal(diag_render_ref, diag_c_file.render()) + assert diag_render_ref == diag_c_file.render() # String inputs input_str_list = [] @@ -297,23 +286,23 @@ def _test_full_files_helper(self, flag_dep=False): # Create from string list diag_str_list = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str_list.create_from_string_list(input_str_list) - nt.assert_equal(diag_render_ref, diag_str_list.render()) + assert diag_render_ref == diag_str_list.render() # Add from string list diag_str_list_add = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str_list_add.add_from_string_list(input_str_list) diag_str_list_add.build_relationship_lists() diag_str_list_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_str_list_add.render()) + assert diag_render_ref == diag_str_list_add.render() # Create from string diag_str = hpp2plantuml.Diagram(flag_dep=flag_dep) diag_str.create_from_string('\n'.join(input_str_list)) - nt.assert_equal(diag_render_ref, diag_str.render()) + assert diag_render_ref == diag_str.render() # Reset and parse diag_str.clear() diag_str.create_from_string('\n'.join(input_str_list)) - nt.assert_equal(diag_render_ref, diag_str.render()) + assert diag_render_ref == diag_str.render() # Manually build object diag_manual_add = hpp2plantuml.Diagram(flag_dep=flag_dep) @@ -325,7 +314,7 @@ def _test_full_files_helper(self, flag_dep=False): diag_manual_add.add_from_string(string_c) diag_manual_add.build_relationship_lists() diag_manual_add.sort_elements() - nt.assert_equal(diag_render_ref, diag_manual_add.render()) + assert diag_render_ref == diag_manual_add.render() def test_main_function(self): #self._test_main_function_helper(False) @@ -348,7 +337,7 @@ def _test_main_function_helper(self, flag_dep=False): saved_ref = self._diag_saved_ref else: saved_ref = self._diag_saved_ref_nodep - nt.assert_equal(saved_ref, output_str) + assert saved_ref == output_str # Output to file output_fname = 'output.puml' @@ -362,10 +351,10 @@ def _test_main_function_helper(self, flag_dep=False): output_fcontent = fid.read() if template is None: # Default template check - nt.assert_equal(saved_ref, output_fcontent) + assert saved_ref == output_fcontent else: # Check that all lines of reference are in the output - ref_re = re.search('(@startuml)\s*(.*)', saved_ref, re.DOTALL) + ref_re = re.search(r'(@startuml)\s*(.*)', saved_ref, re.DOTALL) assert ref_re # Build regular expression: allow arbitrary text between # @startuml and the rest of the string @@ -375,5 +364,5 @@ def _test_main_function_helper(self, flag_dep=False): '.*', # preamble re.escape(ref_groups[1])]), # main output re.DOTALL) - nt.assert_true(match_re.search(output_fcontent)) + assert match_re.search(output_fcontent) os.unlink(output_fname)