././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9597797 changelog_chug-0.0.3/0000775000175000017500000000000014707056352014360 5ustar00bignosebignose././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1728597470.0 changelog_chug-0.0.3/COPYING0000664000175000017500000000146014702046736015414 0ustar00bignosebignoseCopying this work ################# changelog-chug is `free software`_; you are free to redistribute it and/or modify it under specific conditions. .. _free software: https://www.gnu.org/philosophy/free-sw.html Software ======== Copyright © 2008–2023 Ben Finney This is free software: you may copy, modify, and/or redistribute this work under the terms of the GNU Affero General Public License as published by the Free Software Foundation; version 3 of that license or any later version. No warranty expressed or implied. See the file `LICENSE.AGPL-3`_ for details, or online at ``_. .. _LICENSE.AGPL-3: LICENSE.AGPL-3 .. Local variables: coding: utf-8 mode: rst End: vim: fileencoding=utf-8 filetype=rst : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729911847.0 changelog_chug-0.0.3/ChangeLog0000664000175000017500000000300014707056047016124 0ustar00bignosebignoseThis document is the `change log`_ for this distribution. It is a record of all notable changes in each version released. Version strings conform to the `Semantic Versioning`_ specification, `version 2.0.0 `__. .. _change log: https://keepachangelog.com/ .. _Semantic Versioning: https://semver.org/ Version 0.0.3 ============= :Released: 2024-10-26 :Maintainer: Ben Finney Bugs fixed: * Correct the programmer representation of a `ChangeLogEntry` object. Previously the `version` value was showing an unrelated value. Changed: * Refine specification of valid `ChangeLogEntry` fields. * Use explicit default values for entry fields. Version 0.0.2 ============= :Released: 2024-10-25 :Maintainer: Ben Finney Initial release. .. This document is written using `reStructuredText`_ markup, and can be rendered with `Docutils`_ to other formats. .. _Docutils: https://docutils.sourceforge.io/ .. _reStructuredText: https://docutils.sourceforge.io/rst.html .. This is free software: you may copy, modify, and/or redistribute this work under the terms of the GNU Affero General Public License as published by the Free Software Foundation; version 3 of that license or any later version. No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. .. Local variables: coding: utf-8 mode: text mode: rst End: vim: fileencoding=utf-8 filetype=rst : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1728597470.0 changelog_chug-0.0.3/LICENSE.AGPL-30000664000175000017500000010333014702046736016247 0ustar00bignosebignose GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Remote Network Interaction; Use with the GNU General Public License. Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see . ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1728597599.0 changelog_chug-0.0.3/MANIFEST.in0000664000175000017500000000057614702047137016122 0ustar00bignosebignose# MANIFEST.in # Template for the source manifest for this distribution. # Documentation: . include LICENSE.* include ChangeLog recursive-include util *.py recursive-include test *.py # Local variables: # coding: utf-8 # mode: conf-space # End: # vim: fileencoding=utf-8 filetype=conf : ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9597797 changelog_chug-0.0.3/PKG-INFO0000644000175000017500000001433414707056352015460 0ustar00bignosebignoseMetadata-Version: 2.1 Name: changelog-chug Version: 0.0.3 Summary: Parser library for project Change Log documents. Author-email: Ben Finney Maintainer: Ben Finney License: Copying this work ################# changelog-chug is `free software`_; you are free to redistribute it and/or modify it under specific conditions. .. _free software: https://www.gnu.org/philosophy/free-sw.html Software ======== Copyright © 2008–2023 Ben Finney This is free software: you may copy, modify, and/or redistribute this work under the terms of the GNU Affero General Public License as published by the Free Software Foundation; version 3 of that license or any later version. No warranty expressed or implied. See the file `LICENSE.AGPL-3`_ for details, or online at ``_. .. _LICENSE.AGPL-3: LICENSE.AGPL-3 .. Local variables: coding: utf-8 mode: rst End: vim: fileencoding=utf-8 filetype=rst : Project-URL: Home Page, https://git.sr.ht/~bignose/changelog-chug Project-URL: Change Log, https://git.sr.ht/~bignose/changelog-chug/tree/main/item/ChangeLog Project-URL: Source, https://git.sr.ht/~bignose/changelog-chug Project-URL: Issue Tracker, https://todo.sr.ht/~bignose/changelog-chug Keywords: version,changelog,release,packaging Classifier: Development Status :: 2 - Pre-Alpha Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+) Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Build Tools Requires-Python: >=3.7 Description-Content-Type: text/x-rst License-File: LICENSE.AGPL-3 License-File: COPYING Requires-Dist: semver>=3.0.0 Requires-Dist: docutils>=0.21.0 Provides-Extra: static-analysis Requires-Dist: pip-check; extra == "static-analysis" Requires-Dist: mccabe~=0.7; extra == "static-analysis" Requires-Dist: pycodestyle~=2.12; extra == "static-analysis" Requires-Dist: ruff~=0.6; extra == "static-analysis" Provides-Extra: test Requires-Dist: changelog-chug[static-analysis]; extra == "test" Requires-Dist: testtools; extra == "test" Requires-Dist: testscenarios>=0.4; extra == "test" Requires-Dist: coverage; extra == "test" Provides-Extra: devel Requires-Dist: changelog-chug[test]; extra == "devel" Requires-Dist: pyupgrade~=3.17; extra == "devel" Requires-Dist: isort~=5.13; extra == "devel" Provides-Extra: build Requires-Dist: changelog-chug[devel]; extra == "build" Requires-Dist: wheel; extra == "build" Requires-Dist: build; extra == "build" Provides-Extra: publish Requires-Dist: changelog-chug[build]; extra == "publish" Requires-Dist: twine; extra == "publish" changelog-chug is a parser for project Change Log documents. changelog-chug ############## Example ======= Given a reStructuredText document ChangeLog:: Change Log ########## Version 1.0.1 ============= :Released: 2020-01-10 :Maintainer: Cathy Morris … Version 1.0 =========== :Released: 2020-01-10 :Maintainer: Luis Flores … Version 0.2 =========== :Released: 2019-07-04 :Maintainer: Cathy Morris … Version 0.2-alpha1 ================== :Released: 2019-07-04 :Maintainer: Cathy Morris … Version 0.1 =========== :Released: 2019-05-16 :Maintainer: Cathy Morris … Generate Change Log entry data for all versions from the reStructuredText formatted ChangeLog:: >>> import pathlib >>> import pprint >>> import chug.parsers.rest >>> import chug.writers >>> infile_path = pathlib.Path(".", "ChangeLog") >>> document_text = chug.parsers.get_changelog_document_text(infile_path) >>> document = chug.parsers.rest.parse_rest_document_from_text( ... document_text) >>> entries = chug.parsers.rest.make_change_log_entries_from_document( ... document) >>> pprint.pprint([entry.as_version_info_entry() for entry in entries]) [OrderedDict([('release_date', '2020-01-10'), ('version', '1.0.1'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2020-01-10'), ('version', '1.0'), ('maintainer', 'Luis Flores '), ('body', '…')]), OrderedDict([('release_date', '2019-07-04'), ('version', '0.2'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2019-07-04'), ('version', '0.2-alpha1'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2019-05-16'), ('version', '0.1'), ('maintainer', 'Cathy Morris '), ('body', '…')])] Generate a JSON document describing the latest version:: >>> import json >>> latest_entry = entries[0] >>> latest_entry_json = json.dumps( ... latest_entry.as_version_info_entry(), indent=4) >>> print(latest_entry_json) { "release_date": "2020-01-10", "version": "1.0.1", "maintainer": "Cathy Morris ", "body": "\u2026" } Copying ======= changelog-chug is free software. See the file `COPYING`_ for details. .. _COPYING: COPYING .. This document is written using `reStructuredText`_ markup, and can be rendered with `Docutils`_ to other formats. .. _Docutils: http://docutils.sourceforge.net/ .. _reStructuredText: http://docutils.sourceforge.net/rst.html .. Local variables: coding: utf-8 mode: rst End: vim: fileencoding=utf-8 filetype=rst : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729813249.0 changelog_chug-0.0.3/README0000664000175000017500000000640314706555401015241 0ustar00bignosebignosechangelog-chug is a parser for project Change Log documents. changelog-chug ############## Example ======= Given a reStructuredText document ChangeLog:: Change Log ########## Version 1.0.1 ============= :Released: 2020-01-10 :Maintainer: Cathy Morris … Version 1.0 =========== :Released: 2020-01-10 :Maintainer: Luis Flores … Version 0.2 =========== :Released: 2019-07-04 :Maintainer: Cathy Morris … Version 0.2-alpha1 ================== :Released: 2019-07-04 :Maintainer: Cathy Morris … Version 0.1 =========== :Released: 2019-05-16 :Maintainer: Cathy Morris … Generate Change Log entry data for all versions from the reStructuredText formatted ChangeLog:: >>> import pathlib >>> import pprint >>> import chug.parsers.rest >>> import chug.writers >>> infile_path = pathlib.Path(".", "ChangeLog") >>> document_text = chug.parsers.get_changelog_document_text(infile_path) >>> document = chug.parsers.rest.parse_rest_document_from_text( ... document_text) >>> entries = chug.parsers.rest.make_change_log_entries_from_document( ... document) >>> pprint.pprint([entry.as_version_info_entry() for entry in entries]) [OrderedDict([('release_date', '2020-01-10'), ('version', '1.0.1'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2020-01-10'), ('version', '1.0'), ('maintainer', 'Luis Flores '), ('body', '…')]), OrderedDict([('release_date', '2019-07-04'), ('version', '0.2'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2019-07-04'), ('version', '0.2-alpha1'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2019-05-16'), ('version', '0.1'), ('maintainer', 'Cathy Morris '), ('body', '…')])] Generate a JSON document describing the latest version:: >>> import json >>> latest_entry = entries[0] >>> latest_entry_json = json.dumps( ... latest_entry.as_version_info_entry(), indent=4) >>> print(latest_entry_json) { "release_date": "2020-01-10", "version": "1.0.1", "maintainer": "Cathy Morris ", "body": "\u2026" } Copying ======= changelog-chug is free software. See the file `COPYING`_ for details. .. _COPYING: COPYING .. This document is written using `reStructuredText`_ markup, and can be rendered with `Docutils`_ to other formats. .. _Docutils: http://docutils.sourceforge.net/ .. _reStructuredText: http://docutils.sourceforge.net/rst.html .. Local variables: coding: utf-8 mode: rst End: vim: fileencoding=utf-8 filetype=rst : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729908869.0 changelog_chug-0.0.3/pyproject.toml0000664000175000017500000001131714707050205017266 0ustar00bignosebignose# pyproject.toml # Python project metadata and build settings for this code base. # Documentation: # # # [project] # Name of the Python distribution to build. name = "changelog-chug" # Text file containing detailed description of the distribution. readme = { file = "README", content-type = "text/x-rst" } # Keywords to categorise this project. keywords = ["version", "changelog", "release", "packaging"] # Trove classifiers for this project. # Reference: classifiers = [ "Development Status :: 2 - Pre-Alpha", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Programming Language :: Python :: 3", "Intended Audience :: Developers", "Topic :: Software Development :: Build Tools", ] # The Python version requirements of the project. requires-python = ">= 3.7" # Core dependencies required for the package to operate. dependencies = [ # Semantic Versioning implementation. # Documentation: . "semver >= 3.0.0", # Python Documentation Utilities. # Documentation: . "docutils >= 0.21.0", ] # The license granted to recipients of this project. license = { file = "COPYING" } # The persons or entities considered the authors of this project. authors = [ { name = "Ben Finney", email = "ben+python@benfinney.id.au" }, ] # Names of fields that must be dynamically computed by the build system. dynamic = [ "description", "version", "maintainers", ] [project.optional-dependencies] static-analysis = [ # Pip version inspector that reports PyPI available updates. # Homepage: . "pip-check", # McCabe code complexity measurement tool. # Documentation: . "mccabe ~= 0.7", # Static code checker for Python style recommendations. # Documentation: . "pycodestyle ~= 2.12", # Python linter and code formatter. # Documentation: . "ruff ~= 0.6", ] test = [ "changelog-chug[static-analysis]", # Extensions to the Python ‘unittest’ framework. # Documentation: . "testtools", # Data-driven test scenarios for ‘unittest’. # Documentation: . "testscenarios >= 0.4", # Code coverage measurement. # Documentation: . "coverage", ] devel = [ "changelog-chug[test]", # Tool to upgrade Python syntax for newer versions. # Documentation: . "pyupgrade ~= 3.17", # Python ‘import’ statement sorter. # Documentation: . "isort ~= 5.13", ] build = [ "changelog-chug[devel]", # Reference implementation of Python wheel packaging standard (PEP 427). # Documentation: . "wheel", # A simple, correct (defined by PEP 517) Python build frontend. # Documentation: . "build", ] publish = [ "changelog-chug[build]", # Collection of utilities for publishing packages on PyPI. # Documentation: . "twine", ] [project.urls] "Home Page" = "https://git.sr.ht/~bignose/changelog-chug" "Change Log" = """ https://git.sr.ht/~bignose/changelog-chug/tree/main/item/ChangeLog """ "Source" = "https://git.sr.ht/~bignose/changelog-chug" "Issue Tracker" = "https://todo.sr.ht/~bignose/changelog-chug" [build-system] # Minimum requirements for the build system. requires = [ # Framework for working with Python packages. # Documentation: . "setuptools >= 62.4.0", # Semantic Versioning implementation. # Documentation: . "semver >= 3.0.0", # Python Documentation Utilities. # Documentation: . "docutils >= 0.21.0", ] # Path to the Python object to perform the build. build-backend = "setuptools.build_meta" [tool.setuptools.packages.find] # Folders that contain the packages (default: ["."]) where = ["src"] [tool.coverage.run] # Source (packages or directories) to measure during execution. source = [ "src", "util", ] # Local-variables: # coding: utf-8 # mode: conf # mode: toml # End: # vim: fileencoding=utf-8 filetype=toml : ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9597797 changelog_chug-0.0.3/setup.cfg0000664000175000017500000000004614707056352016201 0ustar00bignosebignose[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729813249.0 changelog_chug-0.0.3/setup.py0000664000175000017500000000360014706555401016067 0ustar00bignosebignose# setup.py # Python Setuptools configuration program for this distribution. # Documentation: . # noqa: E501 # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Distribution setup for ‘changelog-chug’ library. """ import pathlib import sys from setuptools import setup # This module is not inside a package, so we can't use relative imports. We # instead add its directory to the import path. package_root_dir = pathlib.Path(__file__).parent sys.path.insert(0, str(package_root_dir)) import util.metadata # noqa: E402 import src.chug as main_module # noqa: E402 main_module_docstring = util.metadata.docstring_from_object(main_module) (synopsis, __) = util.metadata.synopsis_and_description_from_docstring( main_module_docstring) changelog_infile_path = package_root_dir.joinpath("ChangeLog") latest_changelog_entry = util.metadata.get_latest_changelog_entry( changelog_infile_path) setup_kwargs = dict( description=synopsis, version=latest_changelog_entry.version, maintainer=latest_changelog_entry.maintainer, ) if __name__ == '__main__': # pragma: nocover setup(**setup_kwargs) # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3 of that license or any later version. # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9517798 changelog_chug-0.0.3/src/0000775000175000017500000000000014707056352015147 5ustar00bignosebignose././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9557798 changelog_chug-0.0.3/src/changelog_chug.egg-info/0000775000175000017500000000000014707056352021576 5ustar00bignosebignose././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729912041.0 changelog_chug-0.0.3/src/changelog_chug.egg-info/PKG-INFO0000644000175000017500000001433414707056351022675 0ustar00bignosebignoseMetadata-Version: 2.1 Name: changelog-chug Version: 0.0.3 Summary: Parser library for project Change Log documents. Author-email: Ben Finney Maintainer: Ben Finney License: Copying this work ################# changelog-chug is `free software`_; you are free to redistribute it and/or modify it under specific conditions. .. _free software: https://www.gnu.org/philosophy/free-sw.html Software ======== Copyright © 2008–2023 Ben Finney This is free software: you may copy, modify, and/or redistribute this work under the terms of the GNU Affero General Public License as published by the Free Software Foundation; version 3 of that license or any later version. No warranty expressed or implied. See the file `LICENSE.AGPL-3`_ for details, or online at ``_. .. _LICENSE.AGPL-3: LICENSE.AGPL-3 .. Local variables: coding: utf-8 mode: rst End: vim: fileencoding=utf-8 filetype=rst : Project-URL: Home Page, https://git.sr.ht/~bignose/changelog-chug Project-URL: Change Log, https://git.sr.ht/~bignose/changelog-chug/tree/main/item/ChangeLog Project-URL: Source, https://git.sr.ht/~bignose/changelog-chug Project-URL: Issue Tracker, https://todo.sr.ht/~bignose/changelog-chug Keywords: version,changelog,release,packaging Classifier: Development Status :: 2 - Pre-Alpha Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+) Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Build Tools Requires-Python: >=3.7 Description-Content-Type: text/x-rst License-File: LICENSE.AGPL-3 License-File: COPYING Requires-Dist: semver>=3.0.0 Requires-Dist: docutils>=0.21.0 Provides-Extra: static-analysis Requires-Dist: pip-check; extra == "static-analysis" Requires-Dist: mccabe~=0.7; extra == "static-analysis" Requires-Dist: pycodestyle~=2.12; extra == "static-analysis" Requires-Dist: ruff~=0.6; extra == "static-analysis" Provides-Extra: test Requires-Dist: changelog-chug[static-analysis]; extra == "test" Requires-Dist: testtools; extra == "test" Requires-Dist: testscenarios>=0.4; extra == "test" Requires-Dist: coverage; extra == "test" Provides-Extra: devel Requires-Dist: changelog-chug[test]; extra == "devel" Requires-Dist: pyupgrade~=3.17; extra == "devel" Requires-Dist: isort~=5.13; extra == "devel" Provides-Extra: build Requires-Dist: changelog-chug[devel]; extra == "build" Requires-Dist: wheel; extra == "build" Requires-Dist: build; extra == "build" Provides-Extra: publish Requires-Dist: changelog-chug[build]; extra == "publish" Requires-Dist: twine; extra == "publish" changelog-chug is a parser for project Change Log documents. changelog-chug ############## Example ======= Given a reStructuredText document ChangeLog:: Change Log ########## Version 1.0.1 ============= :Released: 2020-01-10 :Maintainer: Cathy Morris … Version 1.0 =========== :Released: 2020-01-10 :Maintainer: Luis Flores … Version 0.2 =========== :Released: 2019-07-04 :Maintainer: Cathy Morris … Version 0.2-alpha1 ================== :Released: 2019-07-04 :Maintainer: Cathy Morris … Version 0.1 =========== :Released: 2019-05-16 :Maintainer: Cathy Morris … Generate Change Log entry data for all versions from the reStructuredText formatted ChangeLog:: >>> import pathlib >>> import pprint >>> import chug.parsers.rest >>> import chug.writers >>> infile_path = pathlib.Path(".", "ChangeLog") >>> document_text = chug.parsers.get_changelog_document_text(infile_path) >>> document = chug.parsers.rest.parse_rest_document_from_text( ... document_text) >>> entries = chug.parsers.rest.make_change_log_entries_from_document( ... document) >>> pprint.pprint([entry.as_version_info_entry() for entry in entries]) [OrderedDict([('release_date', '2020-01-10'), ('version', '1.0.1'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2020-01-10'), ('version', '1.0'), ('maintainer', 'Luis Flores '), ('body', '…')]), OrderedDict([('release_date', '2019-07-04'), ('version', '0.2'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2019-07-04'), ('version', '0.2-alpha1'), ('maintainer', 'Cathy Morris '), ('body', '…')]), OrderedDict([('release_date', '2019-05-16'), ('version', '0.1'), ('maintainer', 'Cathy Morris '), ('body', '…')])] Generate a JSON document describing the latest version:: >>> import json >>> latest_entry = entries[0] >>> latest_entry_json = json.dumps( ... latest_entry.as_version_info_entry(), indent=4) >>> print(latest_entry_json) { "release_date": "2020-01-10", "version": "1.0.1", "maintainer": "Cathy Morris ", "body": "\u2026" } Copying ======= changelog-chug is free software. See the file `COPYING`_ for details. .. _COPYING: COPYING .. This document is written using `reStructuredText`_ markup, and can be rendered with `Docutils`_ to other formats. .. _Docutils: http://docutils.sourceforge.net/ .. _reStructuredText: http://docutils.sourceforge.net/rst.html .. Local variables: coding: utf-8 mode: rst End: vim: fileencoding=utf-8 filetype=rst : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729912041.0 changelog_chug-0.0.3/src/changelog_chug.egg-info/SOURCES.txt0000664000175000017500000000121314707056351023456 0ustar00bignosebignoseCOPYING ChangeLog LICENSE.AGPL-3 MANIFEST.in README pyproject.toml setup.py src/changelog_chug.egg-info/PKG-INFO src/changelog_chug.egg-info/SOURCES.txt src/changelog_chug.egg-info/dependency_links.txt src/changelog_chug.egg-info/requires.txt src/changelog_chug.egg-info/top_level.txt src/chug/__init__.py src/chug/model.py src/chug/writers.py src/chug/parsers/__init__.py src/chug/parsers/core.py src/chug/parsers/rest.py test/__init__.py test/chug/__init__.py test/chug/test_model.py test/chug/test_parsers.py test/chug/test_parsers_rest.py test/chug/test_writers.py test/util/__init__.py test/util/test_metadata.py util/__init__.py util/metadata.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729912041.0 changelog_chug-0.0.3/src/changelog_chug.egg-info/dependency_links.txt0000664000175000017500000000000114707056351025643 0ustar00bignosebignose ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729912041.0 changelog_chug-0.0.3/src/changelog_chug.egg-info/requires.txt0000664000175000017500000000047614707056351024204 0ustar00bignosebignosesemver>=3.0.0 docutils>=0.21.0 [build] changelog-chug[devel] wheel build [devel] changelog-chug[test] pyupgrade~=3.17 isort~=5.13 [publish] changelog-chug[build] twine [static-analysis] pip-check mccabe~=0.7 pycodestyle~=2.12 ruff~=0.6 [test] changelog-chug[static-analysis] testtools testscenarios>=0.4 coverage ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729912041.0 changelog_chug-0.0.3/src/changelog_chug.egg-info/top_level.txt0000664000175000017500000000000514707056351024322 0ustar00bignosebignosechug ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9557798 changelog_chug-0.0.3/src/chug/0000775000175000017500000000000014707056352016075 5ustar00bignosebignose././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1728881555.0 changelog_chug-0.0.3/src/chug/__init__.py0000664000175000017500000000150614703121623020176 0ustar00bignosebignose# src/chug/__init__.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Parser library for project Change Log documents. """ # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation; version 3 or, at your option, a later version. # No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729907615.0 changelog_chug-0.0.3/src/chug/model.py0000664000175000017500000001410614707045637017555 0ustar00bignosebignose# src/chug/model.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Data model for internal representation. """ import collections import datetime import re import textwrap import semver class VersionInvalidError(ValueError): """ Raised when a version representation is formally invalid. """ class DateInvalidError(ValueError): """ Raised when a date representation is formally invalid. """ class PersonDetailsInvalidError(ValueError): """ Raised when a person representation is formally invalid. """ rfc822_person_regex = re.compile(r"^(?P[^<]+) <(?P[^>]+)>$") """ Regular Expression pattern to match a person's contact details. """ class ChangeLogEntry: """ An individual entry from the Change Log document. """ field_names = [ 'release_date', 'version', 'maintainer', 'body', ] date_format = "%Y-%m-%d" default_version = "UNKNOWN" default_release_date = "UNKNOWN" default_maintainer = "UNKNOWN" def __init__( self, release_date=default_release_date, version=default_version, maintainer=default_maintainer, body=None): self.validate_release_date(release_date) self.release_date = release_date self.validate_version(version) self.version = version self.validate_maintainer(maintainer) self.maintainer = maintainer self.body = body def __repr__(self): """ Programmer representation text of this instance. """ body_abbreviated = ( None if self.body is None else textwrap.shorten(self.body, 30)) text = ( "<{0.__class__.__name__}" " release_date: {0.release_date!r}" " version: {0.version!r}" " maintainer: {0.maintainer!r}" " body: {body!r}" ">").format(self, body=body_abbreviated) return text @classmethod def validate_release_date(cls, value): """ Validate the `release_date` value. :param value: The prospective `release_date` value. :return: ``None`` if the value is valid. :raises DateInvalidError: If the value is invalid. """ if value in ["UNKNOWN", "FUTURE"]: # A valid non-date value. return None try: __ = datetime.datetime.strptime(value, ChangeLogEntry.date_format) except (TypeError, ValueError) as exc: raise DateInvalidError(value) from exc # No exception raised; return successfully. return None @classmethod def validate_version(cls, value): """ Validate the `version` value. :param value: The prospective `version` value. :return: ``None`` if the value is valid. :raises VersionInvalidError: If the value is invalid. """ if value in ["UNKNOWN", "NEXT"]: # A valid non-version value. return None try: __ = semver.Version.parse(value, optional_minor_and_patch=True) except (TypeError, ValueError) as exc: raise VersionInvalidError(value) from exc # No exception raised; return successfully. return None @classmethod def validate_maintainer(cls, value): """ Validate the `maintainer` value. :param value: The prospective `maintainer` value. :return: ``None`` if the value is valid. :raises PersonDetailsInvalidError: If the value is invalid. """ if value in ["UNKNOWN"]: # A valid non-person value. return None try: __ = rfc822_person_regex.search(value) except (TypeError, ValueError) as exc: raise PersonDetailsInvalidError( "not a valid person specification {value!r}".format( value=value)) from exc # No exception raised; return successfully. return None @classmethod def make_ordered_dict(cls, fields): """ Make an ordered dict of the fields. """ result = collections.OrderedDict( (name, fields[name]) for name in cls.field_names) return result def as_version_info_entry(self): """ Format the changelog entry as a version info entry. """ fields = vars(self) entry = self.make_ordered_dict(fields) return entry def __eq__(self, other): result = False if isinstance(other, type(self)): self_mapping = self.make_ordered_dict(vars(self)) other_mapping = self.make_ordered_dict(vars(other)) if self_mapping == other_mapping: result = True return result def get_latest_version(versions): """ Get the latest version from a collection of changelog entries. :param versions: A collection of mappings for changelog entries. :return: An ordered mapping of fields for the latest version, if `versions` is non-empty; otherwise, an empty mapping. """ version_info = collections.OrderedDict() versions_by_release_date = { item['release_date']: item for item in versions} if versions_by_release_date: latest_release_date = max(versions_by_release_date.keys()) version_info = ChangeLogEntry.make_ordered_dict( versions_by_release_date[latest_release_date]) return version_info # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation; version 3 or, at your option, a later version. # No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9557798 changelog_chug-0.0.3/src/chug/parsers/0000775000175000017500000000000014707056352017554 5ustar00bignosebignose././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729229281.0 changelog_chug-0.0.3/src/chug/parsers/__init__.py0000664000175000017500000000212514704370741021663 0ustar00bignosebignose# src/chug/parsers/__init__.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Parsers for various input formats of Change Log document. """ from .core import ( InvalidFormatError, entry_title_regex, get_changelog_document_text, parse_person_field, ) __all__ = [ 'InvalidFormatError', 'entry_title_regex', 'get_changelog_document_text', 'parse_person_field', ] # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation; version 3 or, at your option, a later version. # No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729907615.0 changelog_chug-0.0.3/src/chug/parsers/core.py0000664000175000017500000001260714707045637021070 0ustar00bignosebignose# src/chug/parsers/core.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Core functionality for document parsers. """ import collections import re import semver from ..model import rfc822_person_regex class InvalidFormatError(ValueError): """ Raised when the document is not a valid ‘ChangeLog’ document. """ def __init__(self, node, message=None): self.node = node self.message = message def __str__(self): text = "{message}: {source} line {line}".format( message=( self.message if self.message is not None else "(no message)"), source=( self.node.source if ( hasattr(self.node, 'source') and self.node.source is not None ) else "(source unknown)" ), line=( "{:d}".format(self.node.line) if ( hasattr(self.node, 'line') and self.node.line is not None ) else "(unknown)" ), ) return text ParsedPerson = collections.namedtuple('ParsedPerson', ['name', 'email']) """ A person's contact details: name, email address. """ def parse_person_field(value): """ Parse a person field into name and email address. :param value: The text value specifying a person. :return: A `ParsedPerson` instance for the person's details. If the `value` does not match a standard person with email address, the return value has `email` item set to ``None``. """ result = ParsedPerson(name=None, email=None) match = rfc822_person_regex.match(value) if len(value): if match is not None: result = ParsedPerson( name=match.group('name'), email=match.group('email')) else: result = ParsedPerson(name=value, email=None) return result def get_changelog_document_text(infile_path): """ Get the changelog document text from file at `infile_path`. :param infile_path: Filesystem path of the document to read. :return: Text content from the file. """ with open(infile_path, encoding='utf-8') as infile: text = infile.read() return text entry_title_regex = re.compile( r"^version (?P[\w.-]+)$", re.IGNORECASE) """ Regular Expression pattern to match a change log entry title. """ class ChangeLogEntryTitleFormatInvalidError(ValueError): """ Raised when entry title text does not match expected pattern. """ def verify_is_change_log_entry_title( title, *, regex_pattern=entry_title_regex, ): """ Verify that `title` is a valid Change Log entry title. :param title: The title (text) of the change log entry to query. :param regex_pattern: The compiled `re.Pattern` instance to use for matching the `title` text. :return: The version text parsed from `title`. :raises ChangeLogEntryTitleFormatInvalidError: If `title` does not match the expected title format. """ if regex_pattern.match(title) is None: raise ChangeLogEntryTitleFormatInvalidError(title) def get_version_text_from_entry_title( title, *, regex_pattern=entry_title_regex, ): """ Get the version text from the change log entry title text `title`. :param title: The title (text) of the change log entry to query. :param regex_pattern: The compiled `re.Pattern` instance to use for matching the `title` text. :return: The version text parsed from `title`. :raises ChangeLogEntryTitleFormatInvalidError: If `title` does not match the expected title format. The `regex_pattern` is expected to define a 'version' match group that will match only the version text. """ match = regex_pattern.match(title) if match is None: raise ChangeLogEntryTitleFormatInvalidError(title) version_text = match.group('version') return version_text class VersionFormatInvalidError(ValueError): """ Raised when entry version text is invalid for Semantic Version. """ def get_version_from_version_text(version_text): """ Get the `semver.Version` representation of `version_text` :param version_text: :return: A `semver.Version` instance representing the version. :raises VersionFormatInvalidError: If `version_text` does not parse as a Semantic Version value. """ try: version = semver.Version.parse( version_text, optional_minor_and_patch=True) except ValueError as exc: raise VersionFormatInvalidError(version_text) from exc return version # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation; version 3 or, at your option, a later version. # No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729900021.0 changelog_chug-0.0.3/src/chug/parsers/rest.py0000664000175000017500000003635014707026765021117 0ustar00bignosebignose# src/chug/parsers/rest.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Parser features for reStructuredText documents. """ import docutils.core import docutils.nodes from . import core from .. import model def parse_rest_document_from_text(document_text): """ Get the document structure, parsed from `document_text`. :param document_text: Text of the document in reStructuredText format. :return: The Docutils document root node. :raises TypeError: If `document_text` is not a text string. """ if not isinstance(document_text, str): raise TypeError("not a text string: {!r}".format(document_text)) document = docutils.core.publish_doctree(document_text) return document def verify_is_docutils_node(node, *, node_type=docutils.nodes.Node): """ Verify that `node` is a Docutils node of type `node_type`. :param node: The object to inspect. :param node_type: The Docutils node type, or a `tuple of types, for which to test. :return: ``None``. :raises TypeError: If `node` is not an instance of `docutils.nodes.Node`. """ node_type_text = ( "({})".format(", ".join( "‘{}’".format(item.__name__) for item in node_type)) if isinstance(node_type, tuple) else "‘{}’".format(node_type.__name__)) message = ( # The caller did not specify anything more specific than `Node`. "not a Docutils node: {node!r}" if (node_type == docutils.nodes.Node) # Name the node type specified by the caller. else "not a Docutils node of type {type_text}: {node!r}" ).format(node=node, type_text=node_type_text) if not isinstance(node, node_type): raise TypeError(message) def get_node_text(node): """ Get the child text of the `node`. :param node: The `docutils.nodes.Node` instance to query. :return: The child text of `node`. :raises TypeError: If the `node` is not a `docutils.nodes.Node`. :raises ValueError: If the `node` has no `Text` child node. """ verify_is_docutils_node(node) node_text_children = [ child_node for child_node in node.children if isinstance(child_node, docutils.nodes.Text)] if not node_text_children: raise ValueError( "node has no Text children: {!r}".format(node)) result = next(iter(node_text_children)) return result def get_node_title_text(node): """ Get the `node`'s `title` node child text. :param rest_document: Document root, as a `docutils.nodes.document` instance. :return: The text of the `title` node. :raises TypeError: If the `node` is not a `docutils.nodes.Node`. :raises ValueError: If the `node` has no `title` child node. """ verify_is_docutils_node(node) title_nodes = [ child_node for child_node in node.children if isinstance(child_node, docutils.nodes.title)] if not title_nodes: raise ValueError( "node has no ‘title’ children: {!r}".format(node)) title = next(iter(title_nodes)) result = get_node_text(title) return result def get_document_title_text(rest_document): """ Get the document's `title` node child text. :param rest_document: Document root, as a `docutils.nodes.document` instance. :return: The text of the document's `title` node. :raises TypeError: If the `rest_document` is not a `docutils.nodes.document`. :raises ValueError: If the `rest_document` has no `title` child node. """ verify_is_docutils_node(rest_document, node_type=docutils.nodes.document) result = get_node_title_text(rest_document) return result def get_document_subtitle_text(rest_document): """ Get the document's `subtitle` node child text. :param rest_document: Document root, as a `docutils.nodes.document` instance. :return: The text of the document's `subtitle` node, or ``None`` if absent. :raises TypeError: If the `rest_document` is not a `docutils.nodes.document`. """ verify_is_docutils_node(rest_document, node_type=docutils.nodes.document) subtitle_nodes = [ child_node for child_node in rest_document.children if isinstance(child_node, docutils.nodes.subtitle)] if not subtitle_nodes: raise ValueError( "node has no ‘subtitle’ children: {!r}".format(rest_document)) subtitle = next(iter(subtitle_nodes)) result = get_node_text(subtitle) return result def get_top_level_sections(rest_document): """ Get the top-level section objects from `rest_document`. :param rest_document: Document root, as a `docutils.nodes.document` instance. :return: Sequence of `docutils.nodes.section` instances. :raises TypeError: If the `rest_document` is not a `docutils.nodes.document`. """ verify_is_docutils_node(rest_document, node_type=docutils.nodes.document) sections = ( node for node in rest_document.children if isinstance(node, docutils.nodes.section)) return sections def get_version_text_from_changelog_entry(entry_node): """ Get the version text from changelog entry node `entry_node`. :param entry_node: The `docutils.nodes.Node` representing the change log entry. :return: The version text parsed from the `entry_node` title. """ title_text = get_changelog_entry_title_from_node(entry_node) version_text = core.get_version_text_from_entry_title(title_text) return version_text def get_changelog_entry_title_from_node(entry_node): """ Get the title of the change log entry, from `entry_node`. :param entry_node: The `docutils.nodes.Node` representing the change log entry. :return: The title (text) that is the change log entry title. :raises ValueError: If the `node` has no `Text` child node. Because of how Docutils treats some document structures specially, the actual title of the change log entry might be in different places. For a regular `section`, the child `title` node contains the title. If the change log entry happens to be the whole document, the title might be in the `title` child or the `subtitle` child. """ entry_title = None entry_title_match = False try: entry_title = get_node_title_text(entry_node) core.verify_is_change_log_entry_title(entry_title) entry_title_match = True except (ValueError, core.ChangeLogEntryTitleFormatInvalidError): # No direct ‘title’ text matches. if isinstance(entry_node, docutils.nodes.document): try: entry_title = get_document_subtitle_text(entry_node) core.verify_is_change_log_entry_title(entry_title) entry_title_match = True except (ValueError, core.ChangeLogEntryTitleFormatInvalidError): # The document subtitle also doesn't match. # Nothing more to try. pass if not entry_title_match: # No title found in the expected places matched the expected Change Log # entry title pattern. raise ValueError( "no change log entry title found: {!r}".format(entry_node)) return entry_title def get_changelog_entry_nodes_from_document(rest_document): """ Get the nodes from `rest_document` that represent change log entries. :param rest_document: Document root, as a `docutils.nodes.document` instance. :raises TypeError: If the `rest_document` is not a `docutils.nodes.document`. :return: Sequence of `docutils.nodes.Node` instances, each representing a change log entry. """ entry_nodes = list(get_top_level_sections(rest_document)) if not entry_nodes: entry_nodes = [rest_document] for entry_node in entry_nodes: # Verify that the title is a valid change log entry title. # If this fails an exception will raise. __ = get_changelog_entry_title_from_node(entry_node) result = entry_nodes return result field_list_type_by_entry_node_type = { docutils.nodes.document: docutils.nodes.docinfo, docutils.nodes.section: docutils.nodes.field_list, } """ Mapping from Change Log entry node type, to field list node type. Each different node type that can be a Change Log entry, has different child node type for its corresponding field list where we find metadata about the Change Log entry. This mapping allows specifying exactly the child node type we need based on the given Change Log entry. """ def get_field_list_from_entry_node(entry_node): """ Get the field list of metadata for the Change Log `entry_node`. :param entry_node: The `docutils.nodes.Node` representing the Change Log entry. :return: The ‘docutils.nodes.Node’ representing the field list. :raises ValueError: If no field list node was found as a child of `entry_node`. """ verify_is_docutils_node(entry_node, node_type=tuple( field_list_type_by_entry_node_type.keys())) field_list_node_type = field_list_type_by_entry_node_type[ type(entry_node)] field_list_nodes = [ node for node in entry_node.children if isinstance(node, field_list_node_type) ] if not field_list_nodes: raise ValueError( "no ‘field_list’ child found on {!r}".format(entry_node)) return next(iter(field_list_nodes)) def get_field_body_for_name(field_list_node, field_name): """ Get the body of field matching `field_name` in `field_list_node`. :param field_list_node: The `docutils.nodes.Node` representing the field list. :param field_name: The name (text) of the field to match. :return: The ‘docutils.nodes.Node’ representing the field body. :raises KeyError: If no field was found with name matching `field_name`. """ verify_is_docutils_node(field_list_node, node_type=tuple( field_list_type_by_entry_node_type.values())) matching_field_nodes = [ field_node for (field_node, (field_name_node, field_body_node)) in ( (child_node, child_node.children) for child_node in field_list_node.children) if ( isinstance(field_node, docutils.nodes.field) and ( field_name_node.astext().lower() == field_name.lower())) ] if not matching_field_nodes: raise KeyError( "no ‘field’ with name {name!r} in {field_list!r}".format( field_list=field_list_node, name=field_name)) field_node = next(iter(matching_field_nodes)) (__, field_body_node) = field_node.children return field_body_node def get_body_text_from_entry_node(entry_node): """ Get the body text of the Change Log `entry_node`. :param entry_node: The `docutils.nodes.Node` representing the Change Log entry. :return: The text of the body of the Change Log entry. The Change Log entry body is all content in the entry that follows the title, subtitle, and metadata field list. """ verify_is_docutils_node(entry_node, node_type=tuple( field_list_type_by_entry_node_type.keys())) entry_body = docutils.nodes.section() entry_body.children = [ child_node for child_node in entry_node.children if ( not isinstance(child_node, ( docutils.nodes.title, docutils.nodes.subtitle, *field_list_type_by_entry_node_type.values())) )] entry_body_text = entry_body.astext() return entry_body_text def get_release_date_from_node(entry_node): """ Get the value for `release_date` from `entry_node`. :param entry_node: The `docutils.nodes.Node` representing the change log entry. :return: The release date value (text), or "UNKNOWN" if no date. """ field_list_node = get_field_list_from_entry_node(entry_node) try: release_date_field_body = get_field_body_for_name( field_list_node, 'released') release_date_text = release_date_field_body.astext() except KeyError: release_date_text = None result = ( "UNKNOWN" if release_date_text is None else release_date_text) return result def get_maintainer_from_node(entry_node): """ Get the value for `maintainer` from `entry_node`. :param entry_node: The `docutils.nodes.Node` representing the change log entry. :return: The maintainer value (text), or "UNKNOWN" if no person. """ field_list_node = get_field_list_from_entry_node(entry_node) try: maintainer_field_body = get_field_body_for_name( field_list_node, 'maintainer') maintainer_text = maintainer_field_body.astext() except KeyError: maintainer_text = None result = ( "UNKNOWN" if maintainer_text is None else maintainer_text) return result def make_change_log_entry_from_node(entry_node): """ Make a `ChangeLogEntry` from `entry_node`. :param entry_node: The `docutils.nodes.Node` representing the change log entry. :return: A new `models.ChangeLogEntry` representing the Change Log entry. """ verify_is_docutils_node(entry_node, node_type=tuple( field_list_type_by_entry_node_type.keys())) version_text = get_version_text_from_changelog_entry(entry_node) release_date_text = get_release_date_from_node(entry_node) maintainer_text = get_maintainer_from_node(entry_node) body_text = get_body_text_from_entry_node(entry_node) result = model.ChangeLogEntry( release_date=release_date_text, version=version_text, maintainer=maintainer_text, body=body_text, ) return result def make_change_log_entries_from_document(rest_document): """ Make sequence of `ChangeLogEntry` for entries from `rest_document`. :param rest_document: Document root, as a `docutils.nodes.document` instance. :return: A sequence of `models.ChangeLogEntry` instances, representing the Change Log entries from `rest_document`. """ entry_nodes = get_changelog_entry_nodes_from_document(rest_document) entries = [ make_change_log_entry_from_node(entry_node) for entry_node in entry_nodes ] return entries # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation; version 3 or, at your option, a later version. # No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729229281.0 changelog_chug-0.0.3/src/chug/writers.py0000664000175000017500000000223214704370741020143 0ustar00bignosebignose# src/chug/writers.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Version information writers for various output formats. """ import json def serialise_version_info_from_mapping_to_json(version_info): """ Generate the version info as JSON serialised data. :param version_info: Mapping of version info items. :return: The version info serialised to JSON. """ content = json.dumps(version_info, indent=4) return content # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation; version 3 or, at your option, a later version. # No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9557798 changelog_chug-0.0.3/test/0000775000175000017500000000000014707056352015337 5ustar00bignosebignose././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729907528.0 changelog_chug-0.0.3/test/__init__.py0000664000175000017500000000754714707045510017457 0ustar00bignosebignose# test/__init__.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Test suite for this code base. """ import builtins import contextlib import unittest.mock import testtools def make_expected_error_context( testcase, *, expected_error_attr_name='expected_error', expected_error_message_regex_attr_name='expected_error_message_regex', ): """ Make a context for the `testcase.expected_error`, if any. :param testcase: The `TestCase` instance to inspect. :param expected_error_attr_name: Name (text) of an attribute of `testcase` to inspect; the value is the exception type to expect. :param expected_error_message_regex_attr_name: Name (text) of an attribute of `testcase` to inspect; the value is the regex pattern to expect match in the exception object caught. :return: The Python context to wrap test calls. If the `testcase.expected_error` attribute is bound, return a `testtools.ExpectedException` for that exception type; otherwise, return a `contextlib.nullcontext`. If the `testcase.expected_error` attribute is bound and the `testcase.expected_error_message_regex` attribute is bound, use that value as the `value_re` specification of regular expression pattern that must match the exception's message. """ context = contextlib.nullcontext() if hasattr(testcase, expected_error_attr_name): expected_error_message_regex = getattr( testcase, expected_error_message_regex_attr_name, None) context = testtools.ExpectedException( getattr(testcase, expected_error_attr_name), value_re=expected_error_message_regex, ) return context def mock_builtin_open_for_fake_files(testcase, *, fake_file_content_by_path): """ Mock builtin `open` during `testcase`, for specific fake files. :param testcase: The test case during which to mock `open`. :param fake_file_content_by_path: Mapping of `{file_path: fake_file_content}`. Create fake files (`io.StringIO`) containing each `fake_file_content`. Wrap the `builtins.open` function such that, for the specified `file_path` only, a specific mock `open` function will be called, that returns the corresponding fake file; for any unspecified path, the original `builtins.open` will be called as normal. """ testcase.mock_open_by_path = { file_path: unittest.mock.mock_open(read_data=fake_file_content) for (file_path, fake_file_content) in fake_file_content_by_path.items()} open_orig = builtins.open def fake_open(file, *args, **kwargs): """ Wrapper for builtin `open`, faking for specific paths. """ open_func = ( testcase.mock_open_by_path[file] if file in testcase.mock_open_by_path else open_orig) return open_func(file, *args, **kwargs) testcase.open_patcher = unittest.mock.patch.object( builtins, 'open', side_effect=fake_open) testcase.open_patcher.start() testcase.addCleanup(testcase.open_patcher.stop) # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation; version 3 or, at your option, a later version. # No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1729912041.9557798 changelog_chug-0.0.3/test/chug/0000775000175000017500000000000014707056352016265 5ustar00bignosebignose././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729907528.0 changelog_chug-0.0.3/test/chug/__init__.py0000664000175000017500000000000014707045510020356 0ustar00bignosebignose././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729907528.0 changelog_chug-0.0.3/test/chug/test_model.py0000664000175000017500000003432614707045510021000 0ustar00bignosebignose# test/chug/test_model.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Unit test for ‘chug.model’ module. """ import collections import contextlib import functools import textwrap import testscenarios import testtools import chug.model class ChangeLogEntry_BaseTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Base class for ‘ChangeLogEntry’ test case classes. """ def expected_error_context(self): """ Make a context manager to expect the nominated error. """ context = contextlib.nullcontext() if hasattr(self, 'expected_error'): context = testtools.ExpectedException(self.expected_error) return context class ChangeLogEntry_TestCase(ChangeLogEntry_BaseTestCase): """ Test cases for ‘ChangeLogEntry’ class. """ def setUp(self): """ Set up test fixtures. """ super().setUp() self.test_instance = chug.model.ChangeLogEntry() def test_instantiate(self): """ New instance of ‘ChangeLogEntry’ should be created. """ self.assertIsInstance( self.test_instance, chug.model.ChangeLogEntry) def test_minimum_zero_arguments(self): """ Initialiser should not require any arguments. """ instance = chug.model.ChangeLogEntry() self.assertIsNot(instance, None) class ChangeLogEntry_release_date_TestCase(ChangeLogEntry_BaseTestCase): """ Test cases for ‘ChangeLogEntry.release_date’ attribute. """ scenarios = [ ('default', { 'test_args': {}, 'expected_release_date': chug.model.ChangeLogEntry.default_release_date, }), ('unknown token', { 'test_args': {'release_date': "UNKNOWN"}, 'expected_release_date': "UNKNOWN", }), ('future token', { 'test_args': {'release_date': "FUTURE"}, 'expected_release_date': "FUTURE", }), ('2001-01-01', { 'test_args': {'release_date': "2001-01-01"}, 'expected_release_date': "2001-01-01", }), ('none', { 'test_args': {'release_date': None}, 'expected_error': chug.model.DateInvalidError, }), ('bogus', { 'test_args': {'release_date': "b0gUs"}, 'expected_error': chug.model.DateInvalidError, }), ] def test_has_expected_release_date(self): """ Should have default `release_date` attribute. """ with self.expected_error_context(): instance = chug.model.ChangeLogEntry(**self.test_args) if hasattr(self, 'expected_release_date'): self.assertEqual(self.expected_release_date, instance.release_date) class ChangeLogEntry_version_TestCase(ChangeLogEntry_BaseTestCase): """ Test cases for ‘ChangeLogEntry.version’ attribute. """ scenarios = [ ('default', { 'test_args': {}, 'expected_version': chug.model.ChangeLogEntry.default_version, }), ('unknown token', { 'test_args': {'version': "UNKNOWN"}, 'expected_version': "UNKNOWN", }), ('next token', { 'test_args': {'version': "NEXT"}, 'expected_version': "NEXT", }), ('0.0', { 'test_args': {'version': "0.0"}, 'expected_version': "0.0", }), ('1.2.3', { 'test_args': {'version': "1.2.3"}, 'expected_version': "1.2.3", }), ('1.23.456', { 'test_args': {'version': "1.23.456"}, 'expected_version': "1.23.456", }), ('1.23.456a5', { 'test_args': {'version': "1.23.456a5"}, 'expected_error': chug.model.VersionInvalidError, }), ('1.23.456-alpha5', { 'test_args': {'version': "1.23.456-alpha5"}, 'expected_version': "1.23.456-alpha5", }), ('123.456.789', { 'test_args': {'version': "123.456.789"}, 'expected_version': "123.456.789", }), ('none', { 'test_args': {'version': None}, 'expected_error': chug.model.VersionInvalidError, }), ('non-number', { 'test_args': {'version': "b0gUs"}, 'expected_error': chug.model.VersionInvalidError, }), ('negative', { 'test_args': {'version': "-1.0"}, 'expected_error': chug.model.VersionInvalidError, }), ('non-number parts', { 'test_args': {'version': "1.b0gUs.0"}, 'expected_error': chug.model.VersionInvalidError, }), ] def test_has_expected_version(self): """ Should have default `version` attribute. """ with self.expected_error_context(): instance = chug.model.ChangeLogEntry(**self.test_args) if hasattr(self, 'expected_version'): self.assertEqual(self.expected_version, instance.version) class ChangeLogEntry_maintainer_TestCase(ChangeLogEntry_BaseTestCase): """ Test cases for ‘ChangeLogEntry.maintainer’ attribute. """ scenarios = [ ('default', { 'test_args': {}, 'expected_maintainer': chug.model.ChangeLogEntry.default_maintainer, }), ('unknown token', { 'test_args': {'maintainer': "UNKNOWN"}, 'expected_maintainer': "UNKNOWN", }), ('person', { 'test_args': {'maintainer': "Foo Bar "}, 'expected_maintainer': "Foo Bar ", }), ('malformed', { 'test_args': {'maintainer': "b0gUs ><"}, 'expected_maintainer': "b0gUs ><", }), ('none', { 'test_args': {'maintainer': None}, 'expected_error': chug.model.PersonDetailsInvalidError, }), ] def test_has_expected_maintainer(self): """ Should have default `maintainer` attribute. """ with self.expected_error_context(): instance = chug.model.ChangeLogEntry(**self.test_args) if hasattr(self, 'expected_maintainer'): self.assertEqual(self.expected_maintainer, instance.maintainer) class ChangeLogEntry_body_TestCase(ChangeLogEntry_BaseTestCase): """ Test cases for ‘ChangeLogEntry.body’ attribute. """ scenarios = [ ('default', { 'test_args': {}, 'expected_body': None, }), ('simple', { 'test_args': {'body': "Foo bar baz."}, 'expected_body': "Foo bar baz.", }), ] def test_has_expected_body(self): """ Should have default `body` attribute. """ instance = chug.model.ChangeLogEntry(**self.test_args) self.assertEqual(self.expected_body, instance.body) class ChangeLogEntry_repr_TestCase( ChangeLogEntry_BaseTestCase): """ Test cases for ‘ChangeLogEntry.__repr__’ method. """ scenarios = [ ('default', { 'test_args': {}, 'expected_repr': ( ""), }), ('simple', { 'test_args': { 'version': "2.7.5", 'release_date': "2017-05-25", 'maintainer': "Cathy Morris ", 'body': "Foo bar baz.", }, 'expected_repr': ( "'" " body: 'Foo bar baz.'" ">"), }), ('body-too-long', { 'test_args': { 'version': "2.7.5", 'release_date': "2017-05-25", 'maintainer': "Cathy Morris ", 'body': textwrap.dedent("""\ Aenean non elementum arcu. Sed mattis, quam eu interdum convallis, augue velit dignissim arcu, sed luctus mi velit in nisi. """), }, 'expected_repr': ( "'" " body: 'Aenean non elementum [...]'" ">"), }), ] def test_has_expected_repr(self): """ Should have expected programmer representation. """ instance = chug.model.ChangeLogEntry(**self.test_args) result = repr(instance) self.assertEqual(self.expected_repr, result) class ChangeLogEntry_eq_TestCase( ChangeLogEntry_BaseTestCase): """ Test cases for ‘ChangeLogEntry.__eq__’ method. """ scenarios = [ ('identical', { 'test_instance': chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar ", body="* Donec venenatis nisl aliquam ipsum.\n", ), 'test_other': chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar ", body="* Donec venenatis nisl aliquam ipsum.\n", ), 'expected_result': True, }), ('all fields different', { 'test_instance': chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar ", body="* Donec venenatis nisl aliquam ipsum.\n", ), 'test_other': chug.model.ChangeLogEntry( release_date="2001-01-01", version="0.7.2", maintainer="Foo Bar ", body="* Pellentesque elementum mollis finibus.\n", ), 'expected_result': False, }), ('different types', { 'test_instance': chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar ", body="* Donec venenatis nisl aliquam ipsum.\n", ), 'test_other': { 'release_date': "2004-01-01", 'version': "0.8", 'maintainer': "Foo Bar ", 'body': "* Donec venenatis nisl aliquam ipsum.\n", }, 'expected_result': False, }), ] def test_compares_equality_as_expected(self): """ Should compare for equality as expected. """ result = (self.test_instance == self.test_other) self.assertEqual(self.expected_result, result) class ChangeLogEntry_as_version_info_entry_TestCase( ChangeLogEntry_BaseTestCase): """ Test cases for ‘ChangeLogEntry.as_version_info_entry’ attribute. """ scenarios = [ ('default', { 'test_args': {}, 'expected_result': collections.OrderedDict([ ( 'release_date', chug.model.ChangeLogEntry.default_release_date), ('version', chug.model.ChangeLogEntry.default_version), ('maintainer', chug.model.ChangeLogEntry.default_maintainer), ('body', None), ]), }), ] def setUp(self): """ Set up test fixtures. """ super().setUp() self.test_instance = chug.model.ChangeLogEntry(**self.test_args) def test_returns_expected_result(self): """ Should return expected result. """ result = self.test_instance.as_version_info_entry() self.assertEqual(self.expected_result, result) DefaultNoneDict = functools.partial(collections.defaultdict, lambda: None) class get_latest_version_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_latest_version’ function. """ scenarios = [ ('simple', { 'test_versions': [ DefaultNoneDict({'release_date': "LATEST"}), ], 'expected_result': chug.model.ChangeLogEntry.make_ordered_dict( DefaultNoneDict({'release_date': "LATEST"})), }), ('no versions', { 'test_versions': [], 'expected_result': collections.OrderedDict(), }), ('ordered versions', { 'test_versions': [ DefaultNoneDict({'release_date': "1"}), DefaultNoneDict({'release_date': "2"}), DefaultNoneDict({'release_date': "LATEST"}), ], 'expected_result': chug.model.ChangeLogEntry.make_ordered_dict( DefaultNoneDict({'release_date': "LATEST"})), }), ('un-ordered versions', { 'test_versions': [ DefaultNoneDict({'release_date': "2"}), DefaultNoneDict({'release_date': "LATEST"}), DefaultNoneDict({'release_date': "1"}), ], 'expected_result': chug.model.ChangeLogEntry.make_ordered_dict( DefaultNoneDict({'release_date': "LATEST"})), }), ] def test_returns_expected_result(self): """ Should return expected result. """ result = chug.model.get_latest_version(self.test_versions) self.assertDictEqual(self.expected_result, result) # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3 of that license or any later version. # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729907615.0 changelog_chug-0.0.3/test/chug/test_parsers.py0000664000175000017500000003164114707045637021366 0ustar00bignosebignose# test/chug/test_parsers.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Test cases for ‘chug.parsers’ package. """ import re import textwrap import semver import testscenarios import testtools import chug.parsers from chug.parsers.core import ( ChangeLogEntryTitleFormatInvalidError, VersionFormatInvalidError, ) import chug.parsers.core from .. import ( make_expected_error_context, mock_builtin_open_for_fake_files, ) class FakeNode: """ A fake instance of a `Node` of a document. """ def __init__(self, source=None, line=None): self.source = source self.line = line class InvalidFormatError_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for class `InvalidFormatError`. """ message_scenarios = [ ('message-specified', { 'test_message': "Lorem ipsum, dolor sit amet.", 'expected_message': "Lorem ipsum, dolor sit amet.", 'expected_message_text': "Lorem ipsum, dolor sit amet.", }), ('message-unspecified', { 'test_message': NotImplemented, 'expected_message': None, 'expected_message_text': "(no message)", }), ] node_scenarios = [ ('node-with-source-and-line', { 'test_node': FakeNode(source="consecteur", line=17), 'expected_node_source_text': "consecteur", 'expected_node_text': "consecteur line 17", }), ('node-with-source-only', { 'test_node': FakeNode(source="consecteur"), 'expected_node_source_text': "consecteur", 'expected_node_text': "consecteur line (unknown)", }), ('node-with-line-only', { 'test_node': FakeNode(line=17), 'expected_node_source_text': "(source unknown)", 'expected_node_text': "(source unknown) line 17", }), ] scenarios = testscenarios.multiply_scenarios( message_scenarios, node_scenarios) def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_kwargs = {} self.test_kwargs['node'] = self.test_node if (self.test_message is not NotImplemented): self.test_kwargs['message'] = self.test_message def test_has_specified_node(self): """ Should have specified `node` value. """ test_instance = chug.parsers.InvalidFormatError(**self.test_kwargs) expected_node = self.test_kwargs['node'] self.assertEqual(expected_node, test_instance.node) def test_has_specified_message(self): """ Should have specified `message` value. """ test_instance = chug.parsers.InvalidFormatError(**self.test_kwargs) self.assertEqual(self.expected_message, test_instance.message) def test_str_contains_expected_message_text(self): """ Should have `str` containing expected message text. """ test_instance = chug.parsers.InvalidFormatError(**self.test_kwargs) text = str(test_instance) self.assertIn(self.expected_message_text, text) def test_str_contains_expected_node_text(self): """ Should have `str` containing expected node text. """ test_instance = chug.parsers.InvalidFormatError(**self.test_kwargs) text = str(test_instance) self.assertIn(self.expected_node_text, text) class parse_person_field_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘parse_person_field’ function. """ scenarios = [ ('simple', { 'test_person': "Foo Bar ", 'expected_result': ("Foo Bar", "foo.bar@example.com"), }), ('empty', { 'test_person': "", 'expected_result': (None, None), }), ('none', { 'test_person': None, 'expected_error': TypeError, }), ('no email', { 'test_person': "Foo Bar", 'expected_result': ("Foo Bar", None), }), ] def test_returns_expected_result(self): """ Should return expected result. """ if hasattr(self, 'expected_error'): self.assertRaises( self.expected_error, chug.parsers.parse_person_field, self.test_person) else: result = chug.parsers.parse_person_field(self.test_person) self.assertEqual(self.expected_result, result) class get_changelog_document_text_BaseTestCase(testtools.TestCase): """ Base for test cases for ‘get_changelog_document_text’ function. """ def setUp(self): """ Set up fixtures for this test case. """ super().setUp() mock_builtin_open_for_fake_files( self, fake_file_content_by_path={ self.test_infile_path: self.test_infile_text, }) self.set_test_args() def set_test_args(self): """ Set the `test_args` test case attribute. """ self.test_args = [ self.test_infile_path, ] class get_changelog_document_text_TestCase( testscenarios.WithScenarios, get_changelog_document_text_BaseTestCase): """ Test cases for ‘get_changelog_document_text’ function. """ scenarios = [ ('simple', { 'test_infile_path': "lorem.changelog", 'test_infile_text': textwrap.dedent("""\ lorem ipsum """), }), ] def test_returns_file_text_content(self): """ Should return text content from the input file. """ expected_result = self.test_infile_text result = chug.parsers.get_changelog_document_text(*self.test_args) self.assertEqual(expected_result, result) def make_change_log_entry_title_scenarios(): """ Make a sequence of scenarios for testing Change Log entry titles. :return: Sequence of tuples `(name, parameters)`. Each is a scenario as specified for `testscenarios`. """ scenarios = [ ('title-case', { 'test_args': ["Version 1.0"], 'test_kwargs': {}, 'expected_result': "1.0", }), ('lower-case', { 'test_args': ["version 1.0"], 'test_kwargs': {}, 'expected_result': "1.0", }), ('upper-case', { 'test_args': ["VERSION 1.0"], 'test_kwargs': {}, 'expected_result': "1.0", }), ('title-case regex-custom', { 'test_args': ["Release 1.0"], 'test_kwargs': { 'regex_pattern': re.compile( r"^release (?P[\w.-]+)$", re.IGNORECASE), }, 'expected_result': "1.0", }), ('version-complex', { 'test_args': ["Version 4.0.17-alpha12"], 'test_kwargs': {}, 'expected_result': "4.0.17-alpha12", }), ('empty', { 'test_args': [""], 'test_kwargs': {}, 'expected_error': ChangeLogEntryTitleFormatInvalidError, }), ('version-invalid', { 'test_args': ["Version b%g^s"], 'test_kwargs': {}, 'expected_error': ChangeLogEntryTitleFormatInvalidError, }), ('title-invalid', { 'test_args': ["Elit Aliquam Ipsum"], 'test_kwargs': {}, 'expected_error': ChangeLogEntryTitleFormatInvalidError, }), ('version-invalid regex-custom', { 'test_args': ["Release b%g^s"], 'test_kwargs': { 'regex_pattern': re.compile( r"^release (?P[\w.-]+)$", re.IGNORECASE), }, 'expected_error': ChangeLogEntryTitleFormatInvalidError, }), ('title-invalid', { 'test_args': ["Elit Aliquam Ipsum"], 'test_kwargs': {}, 'expected_error': ChangeLogEntryTitleFormatInvalidError, }), ('not-text', { 'test_args': [object()], 'test_kwargs': {}, 'expected_error': TypeError, }), ] return scenarios class verify_is_change_log_entry_title_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘verify_is_change_log_entry_title’ function. """ function_to_test = staticmethod( chug.parsers.core.verify_is_change_log_entry_title) scenarios = make_change_log_entry_title_scenarios() def test_returns_expected_result_or_raises_error(self): """ Should return or raise expected result or exception. """ with make_expected_error_context(self): self.function_to_test(*self.test_args, **self.test_kwargs) class get_version_text_from_entry_title_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_version_text_from_entry_title’ function. """ function_to_test = staticmethod( chug.parsers.core.get_version_text_from_entry_title) scenarios = make_change_log_entry_title_scenarios() def test_returns_expected_result_or_raises_error(self): """ Should return or raise expected result or exception. """ with make_expected_error_context(self): result = self.function_to_test(*self.test_args, **self.test_kwargs) if hasattr(self, 'expected_result'): self.assertEqual(self.expected_result, result) class get_version_from_version_text_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_version_from_version_text’ function. """ function_to_test = staticmethod( chug.parsers.core.get_version_from_version_text) scenarios = [ ('major-only', { 'test_args': ["1"], 'test_kwargs': {}, 'expected_result': semver.Version.parse( "1", optional_minor_and_patch=True), }), ('major-and-minor-only', { 'test_args': ["1.5"], 'test_kwargs': {}, 'expected_result': semver.Version.parse( "1.5", optional_minor_and_patch=True), }), ('major-minor-patch', { 'test_args': ["1.5.3"], 'test_kwargs': {}, 'expected_result': semver.Version.parse( "1.5.3", optional_minor_and_patch=True), }), ('major-minor-patch-prerelease', { 'test_args': ["1.5.3-beta2"], 'test_kwargs': {}, 'expected_result': semver.Version.parse( "1.5.3-beta2", optional_minor_and_patch=True), }), ('major-minor-patch-build', { 'test_args': ["1.5.3+d3adb33f"], 'test_kwargs': {}, 'expected_result': semver.Version.parse( "1.5.3+d3adb33f", optional_minor_and_patch=True), }), ('major-minor-build', { 'test_args': ["1.5+d3adb33f"], 'test_kwargs': {}, 'expected_result': semver.Version.parse( "1.5+d3adb33f", optional_minor_and_patch=True), }), ] def test_returns_expected_result(self): """ Should return expected result. """ result = self.function_to_test(*self.test_args, **self.test_kwargs) self.assertEqual(self.expected_result, result) class get_version_from_version_text_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘get_version_from_version_text’ function. """ function_to_test = staticmethod( chug.parsers.core.get_version_from_version_text) scenarios = [ ('empty', { 'test_args': [""], 'test_kwargs': {}, 'expected_error': VersionFormatInvalidError, }), ('version-meaningless', { 'test_args': ["b%g^s"], 'test_kwargs': {}, 'expected_error': VersionFormatInvalidError, }), ('version-too-many-components', { 'test_args': ["2.4.6.8"], 'test_kwargs': {}, 'expected_error': VersionFormatInvalidError, }), ] def test_raises_expected_error(self): """ Should raise error of the expected exception type. """ with testtools.ExpectedException(self.expected_error): __ = self.function_to_test(*self.test_args, **self.test_kwargs) # Copyright © 2008–2024 Ben Finney # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3 of that license or any later version. # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1729907615.0 changelog_chug-0.0.3/test/chug/test_parsers_rest.py0000664000175000017500000037111014707045637022421 0ustar00bignosebignose# test/chug/test_parsers_rest.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Test cases for ‘chug.parsers.rest’ module. """ import itertools import textwrap import unittest.mock import docutils.core import docutils.nodes import docutils.utils import semver import testscenarios import testtools import chug.model import chug.parsers.rest from .. import make_expected_error_context def patch_docutils_publish_doctree(testcase, *, fake_document=None): """ Patch function ‘docutils.core.publish_doctree’ during `testcase`. :param testcase: The `TestCase` instance for binding to the patch. :param fake_document: The document to return from the mocked callable. :return: ``None``. """ func_patcher = unittest.mock.patch.object( docutils.core, "publish_doctree", autospec=True) func_patcher.start() testcase.addCleanup(func_patcher.stop) docutils.core.publish_doctree.return_value = fake_document class parse_rest_document_from_text_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘parse_person_field’ function. """ function_to_test = staticmethod( chug.parsers.rest.parse_rest_document_from_text) scenarios = [ ('simple', { 'test_document_text': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. """), }), ('empty', { 'test_document_text': "", }), ('type-none', { 'test_document_text': None, 'expected_error': TypeError, }), ('type-bytes', { 'test_document_text': b"b0gUs", 'expected_error': TypeError, }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() if not hasattr(self, 'test_file_path'): self.test_file_path = self.getUniqueString() self.fake_document_node = docutils.utils.new_document( source_path=self.test_file_path, ) patch_docutils_publish_doctree( self, fake_document=self.fake_document_node) self.test_args = [self.test_document_text] def test_calls_publish_doctree_with_specified_text(self): """ Should call ‘docutils.core.publish_doctree’ with the document text. """ if hasattr(self, 'expected_error'): self.skipTest("will not use Docutils when input is wrong type") __ = self.function_to_test(*self.test_args) docutils.core.publish_doctree.assert_called_with( self.test_document_text) def test_returns_expected_result(self): """ Should return expected result or raise expected error. """ expected_result = self.fake_document_node with make_expected_error_context(self): result = self.function_to_test(*self.test_args) self.assertEqual(expected_result, result) class verify_is_docutils_node_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘verify_is_docutils_node’ function. """ function_to_test = staticmethod(chug.parsers.rest.verify_is_docutils_node) scenarios = [ ('arbitrary-node', { 'test_args': [docutils.nodes.Element()], 'test_kwargs': {}, 'expected_result': None, }), ('arbitrary-node node-type-title', { 'test_args': [docutils.nodes.Element()], 'test_kwargs': { 'node_type': docutils.nodes.title, }, 'expected_error': TypeError, 'expected_error_message_regex': ".+ Docutils node of type ‘title’", }), ('paragraph-node', { 'test_args': [docutils.nodes.paragraph("")], 'test_kwargs': {}, 'expected_result': None, }), ('paragraph-node node-type-paragraph', { 'test_args': [docutils.nodes.paragraph("")], 'test_kwargs': { 'node_type': docutils.nodes.paragraph, }, 'expected_result': None, }), ('paragraph-node node-type-title', { 'test_args': [docutils.nodes.paragraph("")], 'test_kwargs': { 'node_type': docutils.nodes.title, }, 'expected_error': TypeError, 'expected_error_message_regex': ".+ Docutils node of type ‘title’", }), ('paragraph-node node-types-section-or-document', { 'test_args': [docutils.nodes.paragraph("")], 'test_kwargs': { 'node_type': (docutils.nodes.section, docutils.nodes.document), }, 'expected_error': TypeError, 'expected_error_message_regex': ( r".+ Docutils node of type \(‘section’, ‘document’\)"), }), ('document-node', { 'test_args': [ docutils.nodes.document(settings=None, reporter=None)], 'test_kwargs': {}, 'expected_result': None, }), ('document-node node-type-document', { 'test_args': [ docutils.nodes.document(settings=None, reporter=None)], 'test_kwargs': { 'node_type': docutils.nodes.document, }, 'expected_result': None, }), ('document-node node-type-title', { 'test_args': [ docutils.nodes.document(settings=None, reporter=None)], 'test_kwargs': { 'node_type': docutils.nodes.title, }, 'expected_error': TypeError, 'expected_error_message_regex': ".+ Docutils node of type ‘title’", }), ('not-a-node', { 'test_args': [object()], 'test_kwargs': {}, 'expected_error': TypeError, 'expected_error_message_regex': ".+ Docutils node", }), ('not-a-node node-type-title', { 'test_args': [object()], 'test_kwargs': { 'node_type': docutils.nodes.title, }, 'expected_error': TypeError, 'expected_error_message_regex': ".+ Docutils node of type ‘title’", }), ] def test_returns_expected_result_or_raises_expected_error(self): """ Should return expected result or raise expected error. """ with make_expected_error_context(self): result = self.function_to_test(*self.test_args, **self.test_kwargs) if hasattr(self, 'expected_result'): self.assertEqual(self.expected_result, result) class get_node_text_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_node_text’ function. """ function_to_test = staticmethod(chug.parsers.rest.get_node_text) test_document = docutils.core.publish_doctree(textwrap.dedent("""\ Felis gravida lacinia ##################### Maecenas feugiat nibh sed enim fringilla faucibus. """)) scenarios = [ ('document-title-node', { 'test_args': [next( node for node in test_document.children if isinstance(node, docutils.nodes.title))], 'expected_result': "Felis gravida lacinia", }), ('paragraph-node', { 'test_args': [next( node for node in test_document.children if isinstance(node, docutils.nodes.paragraph))], 'expected_result': ( "Maecenas feugiat nibh sed enim fringilla faucibus."), }), ('node-without-text', { 'test_args': [docutils.nodes.decoration()], 'expected_error': ValueError, }), ('not-a-node', { 'test_args': [object()], 'expected_error': TypeError, }), ] def test_returns_expected_result(self): """ Should return expected result or raise expected error. """ with make_expected_error_context(self): result = self.function_to_test(*self.test_args) if hasattr(self, 'expected_result'): self.assertEqual(self.expected_result, result) class get_node_title_text_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_node_title_text’ function. """ function_to_test = staticmethod(chug.parsers.rest.get_node_title_text) test_document = docutils.core.publish_doctree(textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Sed commodo ipsum ac felis gravida lacinia. Tempus lorem aliquet ==================== Maecenas feugiat nibh sed enim fringilla faucibus. """)) scenarios = [ ('document-node', { 'test_args': [test_document], 'expected_result': "Felis gravida lacinia", }), ('section-node', { 'test_args': [next( node for node in test_document.children if isinstance(node, docutils.nodes.section))], 'expected_result': "Tempus lorem aliquet", }), ('paragraph-node', { 'test_args': [next( node for node in test_document.children if isinstance(node, docutils.nodes.paragraph))], 'expected_error': ValueError, }), ('not-a-node', { 'test_args': [object()], 'expected_error': TypeError, }), ] def test_returns_expected_result(self): """ Should return expected result or raise expected error. """ with make_expected_error_context(self): result = self.function_to_test(*self.test_args) if hasattr(self, 'expected_result'): self.assertEqual(self.expected_result, result) class get_node_title_text_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘get_node_title_text’ function. """ function_to_test = staticmethod(chug.parsers.rest.get_node_title_text) scenarios = [ ('not-a-node', { 'test_args': [object()], 'expected_error': TypeError, }), ] def test_raises_expected_error(self): """ Should raise the `expected_error` type. """ with make_expected_error_context(self): __ = self.function_to_test(*self.test_args) def make_rest_document_test_scenarios(): """ Make a sequence of scenarios for testing different reST documents. :return: Sequence of tuples `(name, parameters)`. Each is a scenario as specified for `testscenarios`. """ scenarios = [ ('entries-one', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # # Therefore there are no top-level `section` nodes. 'expected_document_title_text': "Version 1.0", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ Version 1.0 <docinfo> <field classes="released"> <field_name> Released <field_body> <paragraph> 2009-01-01 <field classes="maintainer"> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ('entries-three', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Pellentesque elementum mollis finibus. """), # There are three sibling top-level sections. Therefore they are # not treated specially. 'expected_document_title_text_error': ValueError, 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_node_id': [ "version-1-0", "version-0-8", "version-0-7-2", ], 'expected_changelog_entries_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), textwrap.dedent("""\ <section ids="version-0-8" names="version\\ 0.8"> <title> version 0.8 <field_list> <field> <field_name> Released <field_body> <paragraph> 2004-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Donec venenatis nisl aliquam ipsum. """), textwrap.dedent("""\ <section ids="version-0-7-2" names="version\\ 0.7.2"> <title> Version 0.7.2 <field_list> <field> <field_name> Released <field_body> <paragraph> 2001-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Pellentesque elementum mollis finibus. """), ], 'expected_versions_text': [ "1.0", "0.8", "0.7.2", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar <foo.bar@example.org>", body="Donec venenatis nisl aliquam ipsum.", ), chug.model.ChangeLogEntry( release_date="2001-01-01", version="0.7.2", maintainer="Foo Bar <foo.bar@example.org>", body="Pellentesque elementum mollis finibus.", ), ], }), ('preamble-paragraph entries-one', { 'test_document_text': textwrap.dedent("""\ Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # The section is not alone at the top level (the preamble paragraph # is its sibling). Therefore the section is not treated specially. 'expected_document_title_text_error': ValueError, 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [ "Version 1.0", ], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ('preamble-paragraph entries-three', { 'test_document_text': textwrap.dedent("""\ Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Pellentesque elementum mollis finibus. """), # The sections are not alone at the top level (the preamble # paragraph is a sibling). Therefore the sections are not treated # specially. 'expected_document_title_text_error': ValueError, 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_node_id': [ "version-1-0", "version-0-8", "version-0-7-2", ], 'expected_changelog_entries_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), textwrap.dedent("""\ <section ids="version-0-8" names="version\\ 0.8"> <title> version 0.8 <field_list> <field> <field_name> Released <field_body> <paragraph> 2004-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Donec venenatis nisl aliquam ipsum. """), textwrap.dedent("""\ <section ids="version-0-7-2" names="version\\ 0.7.2"> <title> Version 0.7.2 <field_list> <field> <field_name> Released <field_body> <paragraph> 2001-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Pellentesque elementum mollis finibus. """), ], 'expected_versions_text': [ "1.0", "0.8", "0.7.2", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar <foo.bar@example.org>", body="Donec venenatis nisl aliquam ipsum.", ), chug.model.ChangeLogEntry( release_date="2001-01-01", version="0.7.2", maintainer="Foo Bar <foo.bar@example.org>", body="Pellentesque elementum mollis finibus.", ), ], }), ('document-title entries-one', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section with lone subsection # specially: their titles are “lifted up to be the document's # (sub)title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore there are no top-level `section`s. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text': "Version 1.0", 'expected_sections_title_text': [], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <document ids="felis-gravida-lacinia" names="felis\\ gravida\\ lacinia" source="<string>" title="Felis gravida lacinia"> <title> Felis gravida lacinia <subtitle ids="version-1-0" names="version\\ 1.0"> Version 1.0 <docinfo> <field classes="released"> <field_name> Released <field_body> <paragraph> 2009-01-01 <field classes="maintainer"> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ('document-title entries-three', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Pellentesque elementum mollis finibus. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore the subsequent sections are the top-level `section`s. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_node_id': [ "version-1-0", "version-0-8", "version-0-7-2", ], 'expected_changelog_entries_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), textwrap.dedent("""\ <section ids="version-0-8" names="version\\ 0.8"> <title> version 0.8 <field_list> <field> <field_name> Released <field_body> <paragraph> 2004-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Donec venenatis nisl aliquam ipsum. """), textwrap.dedent("""\ <section ids="version-0-7-2" names="version\\ 0.7.2"> <title> Version 0.7.2 <field_list> <field> <field_name> Released <field_body> <paragraph> 2001-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Pellentesque elementum mollis finibus. """), ], 'expected_versions_text': [ "1.0", "0.8", "0.7.2", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar <foo.bar@example.org>", body="Donec venenatis nisl aliquam ipsum.", ), chug.model.ChangeLogEntry( release_date="2001-01-01", version="0.7.2", maintainer="Foo Bar <foo.bar@example.org>", body="Pellentesque elementum mollis finibus.", ), ], }), ('document-title preamble-paragraph entries-one', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore the subsequent section is the top-level `section`. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [ "Version 1.0", ], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ('document-title preamble-paragraph entries-three', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Pellentesque elementum mollis finibus. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore the subsequent sections are the top-level `section`s. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_node_id': [ "version-1-0", "version-0-8", "version-0-7-2", ], 'expected_changelog_entries_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), textwrap.dedent("""\ <section ids="version-0-8" names="version\\ 0.8"> <title> version 0.8 <field_list> <field> <field_name> Released <field_body> <paragraph> 2004-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Donec venenatis nisl aliquam ipsum. """), textwrap.dedent("""\ <section ids="version-0-7-2" names="version\\ 0.7.2"> <title> Version 0.7.2 <field_list> <field> <field_name> Released <field_body> <paragraph> 2001-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Pellentesque elementum mollis finibus. """), ], 'expected_versions_text': [ "1.0", "0.8", "0.7.2", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar <foo.bar@example.org>", body="Donec venenatis nisl aliquam ipsum.", ), chug.model.ChangeLogEntry( release_date="2001-01-01", version="0.7.2", maintainer="Foo Bar <foo.bar@example.org>", body="Pellentesque elementum mollis finibus.", ), ], }), ('document-title top-sections-one changelog-format-invalid', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Sed commodo ipsum ac felis gravida lacinia. Tempus lorem aliquet #################### Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # The document title has multiple children: a stand-alone paragraph # and another section. The section is a single top-level `section`. # The resulting document has no changelog entries at the top level. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [ "Tempus lorem aliquet", ], 'expected_changelog_entries_node_id': [ "felis-gravida-lacinia", ], 'expected_changelog_entries_title_text': [ "Felis gravida lacinia", ], 'expected_error': ValueError, }), ('document-title top-sections-three changelog-format-invalid', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Sed commodo ipsum ac felis gravida lacinia. Tempus lorem aliquet #################### Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Pellentesque elementum mollis finibus. """), # The document title has multiple children: a stand-alone paragraph # and another section. The section is a single top-level `section`. # The resulting document has no changelog entries at the top level. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [ "Tempus lorem aliquet", ], 'expected_changelog_entries_node_id': [ "felis-gravida-lacinia", ], 'expected_changelog_entries_title_text': [ "Felis gravida lacinia", ], 'expected_error': ValueError, }), ('document-title-and-subtitle entries-one', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Tempus lorem aliquet #################### Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section with lone subsection # specially: their titles are “lifted up to be the document's # (sub)title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore the subsequent section is the top-level `section`. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text': "Tempus lorem aliquet", 'expected_sections_title_text': [ "Version 1.0", ], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ('document-title-and-subtitle entries-three', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Tempus lorem aliquet #################### Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Pellentesque elementum mollis finibus. """), # Docutils treats a lone top-level section with lone subsection # specially: their titles are “lifted up to be the document's # (sub)title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore the subsequent sections are the top-level `section`s. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text': "Tempus lorem aliquet", 'expected_sections_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_node_id': [ "version-1-0", "version-0-8", "version-0-7-2", ], 'expected_changelog_entries_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), textwrap.dedent("""\ <section ids="version-0-8" names="version\\ 0.8"> <title> version 0.8 <field_list> <field> <field_name> Released <field_body> <paragraph> 2004-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Donec venenatis nisl aliquam ipsum. """), textwrap.dedent("""\ <section ids="version-0-7-2" names="version\\ 0.7.2"> <title> Version 0.7.2 <field_list> <field> <field_name> Released <field_body> <paragraph> 2001-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Pellentesque elementum mollis finibus. """), ], 'expected_versions_text': [ "1.0", "0.8", "0.7.2", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar <foo.bar@example.org>", body="Donec venenatis nisl aliquam ipsum.", ), chug.model.ChangeLogEntry( release_date="2001-01-01", version="0.7.2", maintainer="Foo Bar <foo.bar@example.org>", body="Pellentesque elementum mollis finibus.", ), ], }), ('document-title-and-subtitle preamble-paragraph entries-one', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Tempus lorem aliquet #################### Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section with lone subsection # specially: their titles are “lifted up to be the document's # (sub)title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore the subsequent section is the top-level `section`. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text': "Tempus lorem aliquet", 'expected_sections_title_text': [ "Version 1.0", ], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ('document-title-and-subtitle preamble-paragraph entries-three', { 'test_document_text': textwrap.dedent("""\ ##################### Felis gravida lacinia ##################### Tempus lorem aliquet #################### Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> * Pellentesque elementum mollis finibus. """), # Docutils treats a lone top-level section with lone subsection # specially: their titles are “lifted up to be the document's # (sub)title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore the subsequent sections are the top-level `section`s. 'expected_document_title_text': "Felis gravida lacinia", 'expected_document_subtitle_text': "Tempus lorem aliquet", 'expected_sections_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_node_id': [ "version-1-0", "version-0-8", "version-0-7-2", ], 'expected_changelog_entries_title_text': [ "Version 1.0", "version 0.8", "Version 0.7.2", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <section ids="version-1-0" names="version\\ 1.0"> <title> Version 1.0 <field_list> <field> <field_name> Released <field_body> <paragraph> 2009-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), textwrap.dedent("""\ <section ids="version-0-8" names="version\\ 0.8"> <title> version 0.8 <field_list> <field> <field_name> Released <field_body> <paragraph> 2004-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Donec venenatis nisl aliquam ipsum. """), textwrap.dedent("""\ <section ids="version-0-7-2" names="version\\ 0.7.2"> <title> Version 0.7.2 <field_list> <field> <field_name> Released <field_body> <paragraph> 2001-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Pellentesque elementum mollis finibus. """), ], 'expected_versions_text': [ "1.0", "0.8", "0.7.2", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), chug.model.ChangeLogEntry( release_date="2004-01-01", version="0.8", maintainer="Foo Bar <foo.bar@example.org>", body="Donec venenatis nisl aliquam ipsum.", ), chug.model.ChangeLogEntry( release_date="2001-01-01", version="0.7.2", maintainer="Foo Bar <foo.bar@example.org>", body="Pellentesque elementum mollis finibus.", ), ], }), ('entries-one maintainer-absent', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore there are no top-level `section` nodes. 'expected_document_title_text': "Version 1.0", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <document ids="version-1-0" names="version\\ 1.0" source="<string>" title="Version 1.0"> <title> Version 1.0 <docinfo> <field classes="released"> <field_name> Released <field_body> <paragraph> 2009-01-01 <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="UNKNOWN", body="Lorem ipsum dolor sit amet.", ), ], }), ('entries-one maintainer-unknown', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: UNKNOWN * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore there are no top-level `section` nodes. 'expected_document_title_text': "Version 1.0", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <document ids="version-1-0" names="version\\ 1.0" source="<string>" title="Version 1.0"> <title> Version 1.0 <docinfo> <field classes="released"> <field_name> Released <field_body> <paragraph> 2009-01-01 <field classes="maintainer"> <field_name> Maintainer <field_body> <paragraph> UNKNOWN <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="2009-01-01", version="1.0", maintainer="UNKNOWN", body="Lorem ipsum dolor sit amet.", ), ], }), ('entries-one release-date-absent', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore there are no top-level `section` nodes. 'expected_document_title_text': "Version 1.0", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <document ids="version-1-0" names="version\\ 1.0" source="<string>" title="Version 1.0"> <title> Version 1.0 <docinfo> <field classes="maintainer"> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="UNKNOWN", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ('entries-one release-date-unknown', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: UNKNOWN :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore there are no top-level `section` nodes. 'expected_document_title_text': "Version 1.0", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <document ids="version-1-0" names="version\\ 1.0" source="<string>" title="Version 1.0"> <title> Version 1.0 <docinfo> <field classes="released"> <field_name> Released <field_body> <paragraph> UNKNOWN <field classes="maintainer"> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="UNKNOWN", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ('entries-one release-date-future', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: FUTURE :Maintainer: Foo Bar <foo.bar@example.org> * Lorem ipsum dolor sit amet. """), # Docutils treats a lone top-level section title specially: it is # “lifted up to be the document's title”. # <URL:https://docutils.sourceforge.io/docs/user/rst/quickref.html> # Therefore there are no top-level `section` nodes. 'expected_document_title_text': "Version 1.0", 'expected_document_subtitle_text_error': ValueError, 'expected_sections_title_text': [], 'expected_changelog_entries_node_id': [ "version-1-0", ], 'expected_changelog_entries_title_text': [ "Version 1.0", ], 'expected_changelog_entries_pformat': [ textwrap.dedent("""\ <document ids="version-1-0" names="version\\ 1.0" source="<string>" title="Version 1.0"> <title> Version 1.0 <docinfo> <field classes="released"> <field_name> Released <field_body> <paragraph> FUTURE <field classes="maintainer"> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > <bullet_list bullet="*"> <list_item> <paragraph> Lorem ipsum dolor sit amet. """), ], 'expected_versions_text': [ "1.0", ], 'expected_change_log_entries': [ chug.model.ChangeLogEntry( release_date="FUTURE", version="1.0", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), ], }), ] for (__, scenario) in scenarios: if 'expected_versions_text' in scenario: scenario['expected_versions'] = [ semver.Version.parse( version_text, optional_minor_and_patch=True) for version_text in scenario['expected_versions_text'] ] return scenarios def make_error_rest_document_test_scenarios(): """ Make a sequence of scenarios for testing errors for reST documents. :return: Sequence of tuples `(name, parameters)`. Each is a scenario as specified for `testscenarios`. """ scenarios = [ ('not-a-node', { 'test_args': [object()], 'expected_error': TypeError, }), ('not-a-document-root', { 'test_args': [docutils.nodes.container( "imperdiet malesuada finibus", docutils.nodes.title("sagittis tincidunt"), docutils.nodes.subtitle("euismod erat viverra"), docutils.nodes.section("euismod eu nunc"), docutils.nodes.section("viverra consectetur ante"), )], 'expected_error': TypeError, }), ] return scenarios class get_document_title_text_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_document_title_text’ function. """ function_to_test = staticmethod(chug.parsers.rest.get_document_title_text) scenarios = make_rest_document_test_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_args = [self.test_document] def test_result_is_expected_title_text(self): """ Should return the expected text of document's `title`, or raise error. """ with make_expected_error_context( self, expected_error_attr_name='expected_document_title_text_error', expected_error_message_regex_attr_name=( 'expected_document_title_text_error_regex') ): result = self.function_to_test(*self.test_args) if hasattr(self, 'expected_document_title_text'): self.assertEqual(self.expected_document_title_text, result) class get_document_title_text_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘get_document_title_text’ function. """ function_to_test = staticmethod(chug.parsers.rest.get_document_title_text) scenarios = make_error_rest_document_test_scenarios() def test_raises_expected_error(self): """ Should raise the `expected_error` type. """ with testtools.ExpectedException(self.expected_error): __ = self.function_to_test(*self.test_args) class get_document_subtitle_text_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_document_subtitle_text’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_document_subtitle_text) scenarios = make_rest_document_test_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_args = [self.test_document] def test_result_is_expected_document_subtitle_text(self): """ Should return the expected text of document's `subtitle`, or error. """ with make_expected_error_context( self, expected_error_attr_name=( 'expected_document_subtitle_text_error'), expected_error_message_regex_attr_name=( 'expected_document_subtitle_text_error_regex') ): result = self.function_to_test(*self.test_args) if hasattr(self, 'expected_document_subtitle_text'): self.assertEqual(self.expected_document_subtitle_text, result) class get_document_subtitle_text_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘get_document_subtitle_text’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_document_subtitle_text) scenarios = make_error_rest_document_test_scenarios() def test_raises_expected_error(self): """ Should raise the `expected_error` type. """ with testtools.ExpectedException(self.expected_error): __ = self.function_to_test(*self.test_args) class get_top_level_sections_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_top_level_sections’ function. """ function_to_test = staticmethod(chug.parsers.rest.get_top_level_sections) scenarios = make_rest_document_test_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_args = [self.test_document] def test_returns_section_nodes(self): """ Should return a sequence of `section` iff we expect any. """ result = self.function_to_test(*self.test_args) expected_type = docutils.nodes.section self.assertTrue( all(isinstance(item, expected_type) for item in result)) def test_result_sections_have_expected_title_child_text(self): """ Should return a sequence of `section`s with expected `title` node text. """ result = self.function_to_test(*self.test_args) result_list = list(result) result_sequence_title = ( next( node for node in section.children if isinstance(node, docutils.nodes.title) ) for section in result_list) result_sequence_title_child_text = ( (next(iter(title.children))) for title in result_sequence_title) self.assertEqual( list(self.expected_sections_title_text), list(result_sequence_title_child_text)) class get_top_level_sections_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘get_top_level_sections’ function. """ function_to_test = staticmethod(chug.parsers.rest.get_top_level_sections) scenarios = make_error_rest_document_test_scenarios() def test_raises_expected_error(self): """ Should raise the `expected_error` type. """ with testtools.ExpectedException(self.expected_error): __ = self.function_to_test(*self.test_args) class get_version_text_from_changelog_entry_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_version_text_from_changelog_entry’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_version_text_from_changelog_entry) scenarios = make_rest_document_test_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) def test_returns_expected_result(self): """ Should return expected result. """ if not hasattr(self, 'expected_versions_text'): self.skipTest("no result expected") self.expected_version_text_by_node_id = dict(zip( self.expected_changelog_entries_node_id, self.expected_versions_text, strict=True, )) self.test_entry_node_by_node_id = make_entry_node_by_node_id( self.test_document, node_ids=self.expected_version_text_by_node_id.keys()) for ( test_node_id, test_entry_node ) in self.test_entry_node_by_node_id.items(): expected_version_text = self.expected_version_text_by_node_id[ test_node_id] with self.subTest( node_id=test_node_id, expected_version_text=expected_version_text, ): test_args = [test_entry_node] result = self.function_to_test(*test_args) self.assertEqual(expected_version_text, result) def has_matching_node_id(node, node_id): """ Return ``True`` iff `node` attribute 'ids' matches `node_id`. :param node: The `docutils.nodes.Node` to query. :param node_id: The node identifier (text) to match. :return: ``True`` iff the `node_id` is in the 'ids' node attribute, otherwise ``False``. """ node_ids_value = node.get('ids') result = bool(node_ids_value and (node_id in node_ids_value)) return result def get_nodes_matching_node_id(nodes, node_id): """ Get the nodes from `nodes` with identifier matching `node_id`. :param nodes: The collection of `docutils.nodes.Node` to query. :param node_id: The node identifier (text) to match. :return: Sequence of nodes whose 'ids' attribute contains a match for `node_id`. :raises ValueError: If no child node matches `node_id`. """ matching_nodes = [ node for node in nodes if has_matching_node_id(node, node_id)] if not matching_nodes: raise ValueError( "no match for {node_id!r} in {nodes!r}".format( nodes=nodes, node_id=node_id)) return matching_nodes def make_entry_node_by_node_id(rest_document, *, node_ids): """ Make a mapping of Change Log entry nodes by identifier. :param rest_document: Document root, as a `docutils.nodes.document` instance. :param node_ids: Sequence of identifiers to match nodes in `rest_document`. :return: A mapping `{node_id: entry_node}` for each item in `node_ids`, where `entry_node` is the Change Log entry node found in `rest_document`. """ entry_node_by_node_id = dict() for node_id in node_ids: for candidate_node in get_nodes_matching_node_id( nodes=itertools.chain( [rest_document], rest_document.children), node_id=node_id ): entry_node = ( candidate_node.parent if isinstance( candidate_node, docutils.nodes.subtitle) else candidate_node) entry_node_by_node_id[node_id] = entry_node return entry_node_by_node_id class get_changelog_entry_title_from_node_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_version_text_from_changelog_entry’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_changelog_entry_title_from_node) scenarios = make_rest_document_test_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.expected_title_by_node_id = dict(zip( self.expected_changelog_entries_node_id, self.expected_changelog_entries_title_text, strict=True, )) self.test_entry_node_by_node_id = make_entry_node_by_node_id( self.test_document, node_ids=self.expected_title_by_node_id.keys()) def test_returns_expected_result_or_raises_expected_error(self): """ Should return expected result or raise expected error. """ for ( test_node_id, test_entry_node ) in self.test_entry_node_by_node_id.items(): with self.subTest(node_id=test_node_id): test_args = [test_entry_node] with make_expected_error_context(self): result = self.function_to_test(*test_args) if not hasattr(self, 'expected_error'): expected_result = self.expected_title_by_node_id[ test_node_id] self.assertEqual(expected_result, result) def normalise_whitespace_to_single_space(text): """ Return normalised rendition of `text` with single space. :param text: The text value to normalise. :return: The normalised text. The rendition replaces each sequence of characters matching '[\n\t ]+' with a single U+0020 SPACE. """ normalised_text = " ".join(( text.replace("\n", " ").replace("\t", " ") ).split()) return normalised_text class DoctreePformatEqual(testtools.matchers.Matcher): """ A matcher to compare the value of Docutils node ‘pformat’ output. """ def __init__(self, expected): self.expected_value = expected self.expected_value_normalised = normalise_whitespace_to_single_space( self.expected_value) def match(self, value): """ Assert the pformat output `value` matches the `expected_value`. """ result = None value_normalised = normalise_whitespace_to_single_space(value) if value_normalised != self.expected_value_normalised: result = DoctreePformatValueMismatch(self.expected_value, value) return result class DoctreePformatValueMismatch(testtools.matchers.Mismatch): """ The specified ‘pformat’ output does not match the expected value. """ def __init__(self, expected, actual): self.expected_value = expected self.actual_value = actual def describe(self): """ Emit a text description of this mismatch. """ text = textwrap.dedent("""\ reference: {expected} actual: {actual} """).format( expected=self.expected_value, actual=self.actual_value) return text class get_changelog_entry_nodes_from_document_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_changelog_entry_nodes_from_document’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_changelog_entry_nodes_from_document) scenarios = make_rest_document_test_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_args = [self.test_document] @staticmethod def normalise_whitespace_to_single_space(text): """ Return normalised rendition of `text` with single space. :param text: The text value to normalise. :return: The normalised text. The rendition replaces each sequence of characters matching '[\n\t ]+' with a single U+0020 SPACE. """ normalised_text = " ".join(( text.replace("\n", " ").replace("\t", " ") ).split()) return normalised_text def test_returns_nodes_with_expected_node_ids(self): """ Should return nodes values with expected 'ids' node attributes. """ with make_expected_error_context(self): result = self.function_to_test(*self.test_args) if hasattr(self, 'expected_changelog_entries_pformat'): for (expected_pformat, node) in zip( self.expected_changelog_entries_pformat, result, strict=True, ): self.assertThat( node.pformat(), DoctreePformatEqual(expected_pformat)) def make_changelog_entry_node_scenarios(): """ Make a sequence of scenarios for testing Change Log entry nodes. :return: Sequence of tuples `(name, parameters)`. Each is a scenario as specified for `testscenarios`. """ rest_document_scenarios = make_rest_document_test_scenarios() scenario_extra_params_by_scenario_name = { 'entries-one': { 'test_change_log_entry_node_id': "version-1-0", 'expected_field_list_pformat': textwrap.dedent("""\ <docinfo> <field classes="released"> <field_name> Released <field_body> <paragraph> 2009-01-01 <field classes="maintainer"> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > """), 'expected_change_log_entry': chug.model.ChangeLogEntry( version="1.0", release_date="2009-01-01", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), }, 'entries-three': { 'test_change_log_entry_node_id': "version-0-7-2", 'expected_field_list_pformat': textwrap.dedent("""\ <field_list> <field> <field_name> Released <field_body> <paragraph> 2001-01-01 <field> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > """), 'expected_change_log_entry': chug.model.ChangeLogEntry( version="0.7.2", release_date="2001-01-01", maintainer="Foo Bar <foo.bar@example.org>", body="Pellentesque elementum mollis finibus.", ), }, 'entries-one release-date-absent': { 'test_change_log_entry_node_id': "version-1-0", 'expected_field_list_pformat': textwrap.dedent("""\ <docinfo> <field classes="maintainer"> <field_name> Maintainer <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > """), 'expected_change_log_entry': chug.model.ChangeLogEntry( version="1.0", release_date="UNKNOWN", maintainer="Foo Bar <foo.bar@example.org>", body="Lorem ipsum dolor sit amet.", ), }, 'entries-one maintainer-absent': { 'test_change_log_entry_node_id': "version-1-0", 'expected_field_list_pformat': textwrap.dedent("""\ <docinfo> <field classes="released"> <field_name> Released <field_body> <paragraph> 2009-01-01 """), 'expected_change_log_entry': chug.model.ChangeLogEntry( version="1.0", release_date="2009-01-01", maintainer="UNKNOWN", body="Lorem ipsum dolor sit amet.", ), }, } scenarios = [ (scenario_name, dict( test_document_text=scenario['test_document_text'], **(scenario_extra_params_by_scenario_name[scenario_name]) )) for (scenario_name, scenario) in rest_document_scenarios if scenario_name in scenario_extra_params_by_scenario_name ] return scenarios def get_node_from_document_by_node_id(rest_document, *, node_id): """ Get the node matching `node_id` `rest_document`. :param rest_document: Document root, as a `docutils.nodes.document` instance. :param node_id: The identifier to match with the target node's 'ids' attribute. :return: The `docutils.nodes.Node` matching the query. :raises ValueError: If no candidate node matches `node_id`. Candidate nodes are: the document node itself, and all its immediate child nodes. """ candidate_nodes = itertools.chain( [rest_document], rest_document.children) matching_nodes = get_nodes_matching_node_id( candidate_nodes, node_id=node_id) result = next(iter(matching_nodes)) return result class get_field_list_from_entry_node_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_field_list_from_entry_node’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_field_list_from_entry_node) scenarios = make_changelog_entry_node_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_change_log_entry_node = get_node_from_document_by_node_id( self.test_document, node_id=self.test_change_log_entry_node_id) self.test_args = [self.test_change_log_entry_node] def test_returns_expected_result(self): """ Should return expected result. """ result = self.function_to_test(*self.test_args) self.assertThat( result.pformat(), DoctreePformatEqual(self.expected_field_list_pformat)) class get_field_list_from_entry_node_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘get_field_list_from_entry_node’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_field_list_from_entry_node) scenarios = [ ('not-a-node', { 'test_document': object(), 'expected_error': TypeError, }), ('empty', { 'test_document': docutils.core.publish_doctree(""), 'expected_error': ValueError, }), ('document-title section-no-field-list', { 'test_document': docutils.core.publish_doctree( textwrap.dedent("""\ Felis gravida lacinia ##################### Maecenas feugiat nibh sed enim fringilla faucibus. """), ), 'expected_error': ValueError, }), ('document-title docinfo-table section-no-field-list', { 'test_document': docutils.core.publish_doctree( textwrap.dedent("""\ Felis gravida lacinia ##################### :Published: 2009-01-01 :License: AGPL-3+ Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== * Lorem ipsum dolor sit amet. """), ), 'test_change_log_entry_node_id': "version-1-0", 'expected_error': ValueError, }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_change_log_entry_node = ( get_node_from_document_by_node_id( self.test_document, node_id=self.test_change_log_entry_node_id) if hasattr(self, 'test_change_log_entry_node_id') else self.test_document) self.test_args = [self.test_change_log_entry_node] def test_raises_expected_error(self): """ Should raise expected error. """ with make_expected_error_context(self): __ = self.function_to_test(*self.test_args) class get_field_body_for_name_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_field_body_for_name’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_field_body_for_name) scenarios = [ ('entries-one fields-three first-field', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Lorem ipsum dolor sit amet. """), 'test_change_log_entry_node_id': "version-1-0", 'test_field_name': "released", 'expected_result_pformat': textwrap.dedent("""\ <field_body> <paragraph> 2009-01-01 """), }), ('entries-one fields-three second-field', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Lorem ipsum dolor sit amet. """), 'test_change_log_entry_node_id': "version-1-0", 'test_field_name': "maintainer", 'expected_result_pformat': textwrap.dedent("""\ <field_body> <paragraph> Foo Bar < <reference refuri="mailto:foo.bar@example.org"> foo.bar@example.org > """), }), ('entries-three fields-three first-field', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Pellentesque elementum mollis finibus. """), 'test_change_log_entry_node_id': "version-0-7-2", 'test_field_name': "released", 'expected_result_pformat': textwrap.dedent("""\ <field_body> <paragraph> 2001-01-01 """), }), ('entries-three fields-three second-field', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Meep Morp <meep.morp@example.org> :License: AGPL-3+ * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Zang Warx <zang.warx@example.org> :License: AGPL-3+ * Pellentesque elementum mollis finibus. """), 'test_change_log_entry_node_id': "version-0-7-2", 'test_field_name': "maintainer", 'expected_result_pformat': textwrap.dedent("""\ <field_body> <paragraph> Zang Warx < <reference refuri="mailto:zang.warx@example.org"> zang.warx@example.org > """), }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_change_log_entry_node = get_node_from_document_by_node_id( self.test_document, node_id=self.test_change_log_entry_node_id) self.test_field_list_node = next(iter( child_node for child_node in self.test_change_log_entry_node.children if isinstance(child_node, ( docutils.nodes.docinfo, docutils.nodes.field_list)) )) self.test_args = [self.test_field_list_node, self.test_field_name] def test_returns_expected_result(self): """ Should return expected result. """ result = self.function_to_test(*self.test_args) self.assertEqual(self.expected_result_pformat, result.pformat()) class get_field_body_for_name_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘get_field_body_for_name’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_field_body_for_name) scenarios = [ ('not-a-node', { 'test_field_list_node': object(), 'test_field_name': "b0gUs", 'expected_error': TypeError, }), ('not-a-field-list-node', { 'test_field_list_node': docutils.nodes.paragraph(), 'test_field_name': "b0gUs", 'expected_error': TypeError, }), ('empty', { 'test_field_list_node': docutils.nodes.field_list(), 'test_field_name': "b0gUs", 'expected_error': KeyError, }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_args = [self.test_field_list_node, self.test_field_name] def test_raises_expected_error(self): """ Should raise expected error. """ with make_expected_error_context(self): __ = self.function_to_test(*self.test_args) class get_body_text_from_entry_node_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘get_body_text_from_entry_node’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_body_text_from_entry_node) scenarios = [ ('entries-one paragraphs-one', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Lorem ipsum dolor sit amet. """), 'test_change_log_entry_node_id': "version-1-0", 'expected_result': "Lorem ipsum dolor sit amet.", }), ('entries-one paragraphs-three', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ Sed rhoncus fermentum dui. * Quisque at est tincidunt, lobortis mi sit amet, lacinia sapien. * Lorem ipsum dolor sit amet. """), 'test_change_log_entry_node_id': "version-1-0", 'expected_result': textwrap.dedent("""\ Sed rhoncus fermentum dui. Quisque at est tincidunt, lobortis mi sit amet, lacinia sapien. Lorem ipsum dolor sit amet."""), }), ('entries-three paragraphs-one', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Pellentesque elementum mollis finibus. """), 'test_change_log_entry_node_id': "version-0-7-2", 'expected_result': "Pellentesque elementum mollis finibus.", }), ('entries-three paragraphs-three', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ * Lorem ipsum dolor sit amet. version 0.8 =========== :Released: 2004-01-01 :Maintainer: Meep Morp <meep.morp@example.org> :License: AGPL-3+ * Donec venenatis nisl aliquam ipsum. Version 0.7.2 ============= :Released: 2001-01-01 :Maintainer: Zang Warx <zang.warx@example.org> :License: AGPL-3+ Maecenas sodales posuere justo, eu rhoncus leo fringilla sit amet. * Nulla purus dui, lacinia ultrices bibendum sit amet, pulvinar vel velit. * Pellentesque elementum mollis finibus. """), 'test_change_log_entry_node_id': "version-0-7-2", 'expected_result': textwrap.dedent("""\ Maecenas sodales posuere justo, eu rhoncus leo fringilla sit amet. Nulla purus dui, lacinia ultrices bibendum sit amet, pulvinar vel velit. Pellentesque elementum mollis finibus."""), }), ('empty', { 'test_document_text': "", 'expected_result': "", }), ('entries-one paragraphs-none', { 'test_document_text': textwrap.dedent("""\ Version 1.0 =========== :Released: 2009-01-01 :Maintainer: Foo Bar <foo.bar@example.org> :License: AGPL-3+ """), 'test_change_log_entry_node_id': "version-1-0", 'expected_result': "", }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_change_log_entry_node = ( get_node_from_document_by_node_id( self.test_document, node_id=self.test_change_log_entry_node_id) if hasattr(self, 'test_change_log_entry_node_id') else self.test_document) self.test_args = [self.test_change_log_entry_node] def test_returns_expected_result(self): """ Should return expected result. """ result = self.function_to_test(*self.test_args) self.assertEqual(self.expected_result, result) class get_body_text_from_entry_node_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘get_body_text_from_entry_node’ function. """ function_to_test = staticmethod( chug.parsers.rest.get_body_text_from_entry_node) scenarios = [ ('not-a-node', { 'test_document': object(), 'expected_error': TypeError, }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_change_log_entry_node = ( get_node_from_document_by_node_id( self.test_document, node_id=self.test_change_log_entry_node_id) if hasattr(self, 'test_change_log_entry_node_id') else self.test_document) self.test_args = [self.test_change_log_entry_node] def test_raises_expected_error(self): """ Should raise expected error. """ with make_expected_error_context(self): __ = self.function_to_test(*self.test_args) class make_change_log_entry_from_node_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘make_change_log_entry_from_node’ function. """ function_to_test = staticmethod( chug.parsers.rest.make_change_log_entry_from_node) scenarios = make_changelog_entry_node_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_change_log_entry_node = get_node_from_document_by_node_id( self.test_document, node_id=self.test_change_log_entry_node_id) self.test_args = [self.test_change_log_entry_node] def test_returns_expected_result(self): """ Should return expected result. """ result = self.function_to_test(*self.test_args) self.assertEqual( self.expected_change_log_entry.as_version_info_entry(), result.as_version_info_entry()) class make_change_log_entry_from_node_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘make_change_log_entry_from_node’ function. """ function_to_test = staticmethod( chug.parsers.rest.make_change_log_entry_from_node) scenarios = [ ('not-a-node', { 'test_document': object(), 'expected_error': TypeError, }), ('empty', { 'test_document': docutils.core.publish_doctree(""), 'expected_error': ValueError, }), ('document-title section-no-field-list', { 'test_document': docutils.core.publish_doctree( textwrap.dedent("""\ Felis gravida lacinia ##################### Maecenas feugiat nibh sed enim fringilla faucibus. """), ), 'expected_error': ValueError, }), ('document-title docinfo-table section-no-field-list', { 'test_document': docutils.core.publish_doctree( textwrap.dedent("""\ Felis gravida lacinia ##################### :Published: 2009-01-01 :License: AGPL-3+ Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== * Lorem ipsum dolor sit amet. """), ), 'test_change_log_entry_node_id': "version-1-0", 'expected_error': ValueError, }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() if hasattr(self, 'test_change_log_entry_node_id'): matching_entry_nodes = make_entry_node_by_node_id( self.test_document, node_ids=[self.test_change_log_entry_node_id]) self.test_change_log_entry_node = matching_entry_nodes[ self.test_change_log_entry_node_id] else: self.test_change_log_entry_node = self.test_document self.test_args = [self.test_change_log_entry_node] def test_raises_expected_error(self): """ Should raise expected error. """ with make_expected_error_context(self): __ = self.function_to_test(*self.test_args) class make_change_log_entries_from_document_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘make_change_log_entries_from_document’ function. """ function_to_test = staticmethod( chug.parsers.rest.make_change_log_entries_from_document) scenarios = make_rest_document_test_scenarios() def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document = docutils.core.publish_doctree( self.test_document_text) self.test_args = [self.test_document] def test_returns_expected_result_or_raises_expected_error(self): """ Should return expected result or raise expected error. """ with make_expected_error_context(self): result = self.function_to_test(*self.test_args) if hasattr(self, 'expected_change_log_entries'): for (expected_change_log_entry, result_item) in zip( self.expected_change_log_entries, result, strict=True, ): self.assertEqual( expected_change_log_entry.as_version_info_entry(), result_item.as_version_info_entry()) class make_change_log_entries_from_document_ErrorTestCase( testscenarios.WithScenarios, testtools.TestCase): """ Error test cases for ‘make_change_log_entries_from_document’. """ function_to_test = staticmethod( chug.parsers.rest.make_change_log_entries_from_document) scenarios = [ ('not-a-node', { 'test_document': object(), 'expected_error': TypeError, }), ('empty', { 'test_document': docutils.core.publish_doctree(""), 'expected_error': ValueError, }), ('document-title section-no-field-list', { 'test_document': docutils.core.publish_doctree( textwrap.dedent("""\ Felis gravida lacinia ##################### Maecenas feugiat nibh sed enim fringilla faucibus. """), ), 'expected_error': ValueError, }), ('document-title docinfo-table section-no-field-list', { 'test_document': docutils.core.publish_doctree( textwrap.dedent("""\ Felis gravida lacinia ##################### :Published: 2009-01-01 :License: AGPL-3+ Maecenas feugiat nibh sed enim fringilla faucibus. Version 1.0 =========== * Lorem ipsum dolor sit amet. """), ), 'test_change_log_entry_node_id': "version-1-0", 'expected_error': ValueError, }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_args = [self.test_document] def test_raises_expected_error(self): """ Should raise expected error. """ with make_expected_error_context(self): __ = self.function_to_test(*self.test_args) # Copyright © 2008–2024 Ben Finney <ben+python@benfinney.id.au> # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3 of that license or any later version. # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@PaxHeader��������������������������������������������������������������������������������������0000000�0000000�0000000�00000000026�00000000000�010213� x����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������22 mtime=1729907528.0 ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������changelog_chug-0.0.3/test/chug/test_writers.py������������������������������������������������������0000664�0001750�0001750�00000004267�14707045510�021400� 0����������������������������������������������������������������������������������������������������ustar�00bignose�������������������������bignose����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������# test/chug/test_writers.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Test cases for ‘chug.writers’ package. """ import json import unittest.mock import testscenarios import testtools import chug.writers @unittest.mock.patch.object(json, "dumps", side_effect=json.dumps) class serialise_version_info_from_mapping_to_json_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘serialise_version_info_from_mapping_to_json’ function. """ scenarios = [ ('simple', { 'test_version_info': {'foo': "spam"}, }), ] for (name, scenario) in scenarios: scenario['fake_json_dump'] = json.dumps(scenario['test_version_info']) scenario['expected_value'] = scenario['test_version_info'] def test_passes_specified_object(self, mock_func_json_dumps): """ Should pass the specified object to `json.dumps`. """ chug.writers.serialise_version_info_from_mapping_to_json( self.test_version_info) mock_func_json_dumps.assert_called_with( self.test_version_info, indent=unittest.mock.ANY) def test_returns_expected_result(self, mock_func_json_dumps): """ Should return expected result. """ mock_func_json_dumps.return_value = self.fake_json_dump result = chug.writers.serialise_version_info_from_mapping_to_json( self.test_version_info) value = json.loads(result) self.assertEqual(self.expected_value, value) # Copyright © 2008–2024 Ben Finney <ben+python@benfinney.id.au> # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation; version 3 or, at your option, a later version. # No warranty expressed or implied. See the file ‘LICENSE.AGPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@PaxHeader��������������������������������������������������������������������������������������0000000�0000000�0000000�00000000034�00000000000�010212� x����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������28 mtime=1729912041.9557798 ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������changelog_chug-0.0.3/test/util/���������������������������������������������������������������������0000775�0001750�0001750�00000000000�14707056352�016314� 5����������������������������������������������������������������������������������������������������ustar�00bignose�������������������������bignose����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@PaxHeader��������������������������������������������������������������������������������������0000000�0000000�0000000�00000000026�00000000000�010213� x����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������22 mtime=1729907528.0 ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������changelog_chug-0.0.3/test/util/__init__.py����������������������������������������������������������0000664�0001750�0001750�00000000000�14707045510�020405� 0����������������������������������������������������������������������������������������������������ustar�00bignose�������������������������bignose����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@PaxHeader��������������������������������������������������������������������������������������0000000�0000000�0000000�00000000026�00000000000�010213� x����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������22 mtime=1729907528.0 ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������changelog_chug-0.0.3/test/util/test_metadata.py�����������������������������������������������������0000664�0001750�0001750�00000020263�14707045510�021502� 0����������������������������������������������������������������������������������������������������ustar�00bignose�������������������������bignose����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������# test/util/test_metadata.py # Part of ‘changelog-chug’, a parser for project Change Log documents. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Unit test for ‘util.metadata’ packaging module. """ import textwrap import testscenarios import testtools from chug import model import util.metadata from .. import mock_builtin_open_for_fake_files class FakeObject: """ A fake object for testing. """ class docstring_from_object_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘docstring_from_object’ function. """ scenarios = [ ('single-line', { 'test_docstring': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. """), 'expected_result': "Lorem ipsum, dolor sit amet.", }), ('synopsis one-paragraph', { 'test_docstring': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. Donec et semper sapien, et faucibus felis. Nunc suscipit quam id lectus imperdiet varius. Praesent mattis arcu in sem laoreet, at tincidunt velit venenatis. """), 'expected_result': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. Donec et semper sapien, et faucibus felis. Nunc suscipit quam id lectus imperdiet varius. Praesent mattis arcu in sem laoreet, at tincidunt velit venenatis."""), }), ('synopsis three-paragraphs', { 'test_docstring': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. Ut ac ultrices turpis. Nam tellus ex, scelerisque ac tellus ac, placerat convallis erat. Nunc id mi libero. Donec et semper sapien, et faucibus felis. Nunc suscipit quam id lectus imperdiet varius. Praesent mattis arcu in sem laoreet, at tincidunt velit venenatis. Suspendisse potenti. Fusce egestas id quam non posuere. Maecenas egestas faucibus elit. Aliquam erat volutpat. """), 'expected_result': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. Ut ac ultrices turpis. Nam tellus ex, scelerisque ac tellus ac, placerat convallis erat. Nunc id mi libero. Donec et semper sapien, et faucibus felis. Nunc suscipit quam id lectus imperdiet varius. Praesent mattis arcu in sem laoreet, at tincidunt velit venenatis. Suspendisse potenti. Fusce egestas id quam non posuere. Maecenas egestas faucibus elit. Aliquam erat volutpat."""), }), ] def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_object = FakeObject() self.test_object.__doc__ = self.test_docstring def test_returns_expected_result(self): """ Should return expected result. """ result = util.metadata.docstring_from_object(self.test_object) self.assertEqual(self.expected_result, result) class synopsis_and_description_from_docstring_TestCase( testscenarios.WithScenarios, testtools.TestCase): """ Test cases for ‘synopsis_and_description_from_docstring’ function. """ scenarios = [ ('single-line', { 'test_docstring': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. """), 'expected_synopsis': "Lorem ipsum, dolor sit amet.", 'expected_description': "", }), ('synopsis one-paragraph', { 'test_docstring': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. Donec et semper sapien, et faucibus felis. Nunc suscipit quam id lectus imperdiet varius. Praesent mattis arcu in sem laoreet, at tincidunt velit venenatis. """), 'expected_synopsis': "Lorem ipsum, dolor sit amet.", 'expected_description': textwrap.dedent("""\ Donec et semper sapien, et faucibus felis. Nunc suscipit quam id lectus imperdiet varius. Praesent mattis arcu in sem laoreet, at tincidunt velit venenatis."""), }), ('synopsis three-paragraphs', { 'test_docstring': textwrap.dedent("""\ Lorem ipsum, dolor sit amet. Ut ac ultrices turpis. Nam tellus ex, scelerisque ac tellus ac, placerat convallis erat. Nunc id mi libero. Donec et semper sapien, et faucibus felis. Nunc suscipit quam id lectus imperdiet varius. Praesent mattis arcu in sem laoreet, at tincidunt velit venenatis. Suspendisse potenti. Fusce egestas id quam non posuere. Maecenas egestas faucibus elit. Aliquam erat volutpat. """), 'expected_synopsis': "Lorem ipsum, dolor sit amet.", 'expected_description': textwrap.dedent("""\ Ut ac ultrices turpis. Nam tellus ex, scelerisque ac tellus ac, placerat convallis erat. Nunc id mi libero. Donec et semper sapien, et faucibus felis. Nunc suscipit quam id lectus imperdiet varius. Praesent mattis arcu in sem laoreet, at tincidunt velit venenatis. Suspendisse potenti. Fusce egestas id quam non posuere. Maecenas egestas faucibus elit. Aliquam erat volutpat."""), }), ] def test_returns_expected_result(self): """ Should return expected result. """ result = util.metadata.synopsis_and_description_from_docstring( self.test_docstring) expected_result = (self.expected_synopsis, self.expected_description) self.assertEqual(expected_result, result) class get_latest_changelog_entry_TestCase(testtools.TestCase): """ Test cases for ‘get_latest_changelog_entry’ function. """ function_to_test = staticmethod(util.metadata.get_latest_changelog_entry) def setUp(self): """ Set up fixtures for this test case. """ super().setUp() self.test_document_path = "/example/path/ChangeLog" self.setup_mock_changelog_file(path=self.test_document_path) self.test_args = [self.test_document_path] def setup_mock_changelog_file(self, path): fake_changelog_file_text = textwrap.dedent("""\ Change Log ########## Version 1.7.2 ============= :Released: 2020-01-10 :Maintainer: Cathy Morris <cathy.morris@example.com> … Version 1.5 =========== :Released: 2019-08-04 :Maintainer: Luis Flores <ayalaian@example.org> … """) mock_builtin_open_for_fake_files( self, fake_file_content_by_path={ path: fake_changelog_file_text, }) def test_returns_expected_result(self): """ Should return expected result. """ result = self.function_to_test(*self.test_args) expected_result = model.ChangeLogEntry( version="1.7.2", release_date="2020-01-10", maintainer="Cathy Morris <cathy.morris@example.com>", body="…", ) self.assertEqual(expected_result, result) # Copyright © 2008–2024 Ben Finney <ben+python@benfinney.id.au> # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3 of that license or any later version. # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@PaxHeader��������������������������������������������������������������������������������������0000000�0000000�0000000�00000000034�00000000000�010212� x����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������28 mtime=1729912041.9557798 ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������changelog_chug-0.0.3/util/��������������������������������������������������������������������������0000775�0001750�0001750�00000000000�14707056352�015335� 5����������������������������������������������������������������������������������������������������ustar�00bignose�������������������������bignose����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@PaxHeader��������������������������������������������������������������������������������������0000000�0000000�0000000�00000000026�00000000000�010213� x����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������22 mtime=1728597567.0 ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������changelog_chug-0.0.3/util/__init__.py���������������������������������������������������������������0000664�0001750�0001750�00000000000�14702047077�017433� 0����������������������������������������������������������������������������������������������������ustar�00bignose�������������������������bignose����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������././@PaxHeader��������������������������������������������������������������������������������������0000000�0000000�0000000�00000000026�00000000000�010213� x����������������������������������������������������������������������������������������������������ustar�00�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������22 mtime=1729900021.0 ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������changelog_chug-0.0.3/util/metadata.py���������������������������������������������������������������0000664�0001750�0001750�00000005532�14707026765�017501� 0����������������������������������������������������������������������������������������������������ustar�00bignose�������������������������bignose����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������# util/metadata.py # Part of ‘changelog-chug’, a parser for software release information. # # This is free software, and you are welcome to redistribute it under # certain conditions; see the end of this file for copyright # information, grant of license, and disclaimer of warranty. """ Functionality to work with project metadata. This module implements ways to derive various project metadata at build time. """ import inspect import pathlib import pydoc import sys # During the build, the ‘chug’ namespace is not available, so we can't use # relative imports. We instead add its directory to the import path. package_root_dir = pathlib.Path(__file__).parent.parent sys.path.insert(0, str(package_root_dir.joinpath('src'))) import chug.parsers.rest # noqa: E402 def docstring_from_object(object): """ Extract the `object` docstring as a simple text string. :param object: The Python object to inspect. :return: The docstring (text), “cleaned” according to :PEP:`257`. """ docstring = inspect.getdoc(object) return docstring def synopsis_and_description_from_docstring(docstring): """ Parse one-line synopsis and long description, from `docstring`. :param docstring: The documentation string (“docstring”, text) to parse. :return: A 2-tuple (`synopsis`, `long_description`) of the values parsed from `docstring`. The `docstring` is expected to be of the form described in :PEP:`257`: > Multi-line docstrings consist of a summary line just like a one-line > docstring, followed by a blank line, followed by a more elaborate > description. """ (synopsis, long_description) = pydoc.splitdoc(docstring) return (synopsis, long_description) def get_latest_changelog_entry(infile_path): """ Get the latest entry data from the changelog at `infile_path`. :param infile_path: The filesystem path (text) from which to read the change log document. :return: The most recent change log entry, as a `chug.ChangeLogEntry`. """ document_text = chug.parsers.get_changelog_document_text(infile_path) document = chug.parsers.rest.parse_rest_document_from_text(document_text) entries = chug.parsers.rest.make_change_log_entries_from_document( document) latest_entry = entries[0] return latest_entry # Copyright © 2008–2024 Ben Finney <ben+python@benfinney.id.au> # # This is free software: you may copy, modify, and/or distribute this work # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3 of that license or any later version. # No warranty expressed or implied. See the file ‘LICENSE.GPL-3’ for details. # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������