| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bb8200e commit 85abf72
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -132,7 +132,7 @@ private static ClassBase CreateClass(Type type) { | |||
| 132 | 132 | ||
| 133 | 133 | // If class has constructors, generate an __doc__ attribute. | |
| 134 | 134 | ||
| 135 | - IntPtr doc; | ||
| 135 | + IntPtr doc = IntPtr.Zero; | ||
| 136 | 136 | Type marker = typeof(DocStringAttribute); | |
| 137 | 137 | Attribute[] attrs = (Attribute[])type.GetCustomAttributes(marker, false); | |
| 138 | 138 | if (attrs.Length == 0) { | |
@@ -160,7 +160,9 @@ private static ClassBase CreateClass(Type type) { | |||
| 160 | 160 | Runtime.PyDict_SetItemString(dict, "__overloads__", ctors.pyHandle); | |
| 161 | 161 | Runtime.PyDict_SetItemString(dict, "Overloads", ctors.pyHandle); | |
| 162 | 162 | } | |
| 163 | - if (!CLRModule._SuppressDocs) | ||
| 163 | + | ||
| 164 | + // don't generate the docstring if one was already set from a DocStringAttribute. | ||
| 165 | + if (!CLRModule._SuppressDocs && doc == IntPtr.Zero) | ||
| 164 | 166 | { | |
| 165 | 167 | doc = co.GetDocString(); | |
| 166 | 168 | Runtime.PyDict_SetItemString(dict, "__doc__", doc); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,6 +119,7 @@ | |||
| 119 | 119 | <Compile Include="methodtest.cs" /> | |
| 120 | 120 | <Compile Include="propertytest.cs" /> | |
| 121 | 121 | <Compile Include="threadtest.cs" /> | |
| 122 | + <Compile Include="doctest.cs" /> | ||
| 122 | 123 | </ItemGroup> | |
| 123 | 124 | <ItemGroup> | |
| 124 | 125 | <Reference Include="System" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,61 @@ | |||
| 1 | + // ========================================================================== | ||
| 2 | + // This software is subject to the provisions of the Zope Public License, | ||
| 3 | + // Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | ||
| 4 | + // THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
| 5 | + // WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| 6 | + // WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
| 7 | + // FOR A PARTICULAR PURPOSE. | ||
| 8 | + // ========================================================================== | ||
| 9 | + | ||
| 10 | + using Python.Runtime; | ||
| 11 | + | ||
| 12 | + namespace Python.Test { | ||
| 13 | + | ||
| 14 | + //======================================================================== | ||
| 15 | + // Supports units tests for exposing docstrings from C# to Python | ||
| 16 | + //======================================================================== | ||
| 17 | + | ||
| 18 | + // Classes with a constructor have their docstring set to the ctor signature. | ||
| 19 | + // Test if a class has an explicit doc string it gets set correctly. | ||
| 20 | + [DocStringAttribute("DocWithCtorTest Class")] | ||
| 21 | + public class DocWithCtorTest { | ||
| 22 | + | ||
| 23 | + public DocWithCtorTest() { | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + [DocStringAttribute("DocWithCtorTest TestMethod")] | ||
| 27 | + public void TestMethod() { | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + [DocStringAttribute("DocWithCtorTest StaticTestMethod")] | ||
| 31 | + public static void StaticTestMethod() { | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public class DocWithCtorNoDocTest | ||
| 37 | + { | ||
| 38 | + public DocWithCtorNoDocTest(bool x) { | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void TestMethod(double a, int b) { | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static void StaticTestMethod(double a, int b) { | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + [DocStringAttribute("DocWithoutCtorTest Class")] | ||
| 49 | + public class DocWithoutCtorTest { | ||
| 50 | + | ||
| 51 | + [DocStringAttribute("DocWithoutCtorTest TestMethod")] | ||
| 52 | + public void TestMethod() { | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + [DocStringAttribute("DocWithoutCtorTest StaticTestMethod")] | ||
| 56 | + public static void StaticTestMethod() { | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,46 @@ | |||
| 1 | + # =========================================================================== | ||
| 2 | + # This software is subject to the provisions of the Zope Public License, | ||
| 3 | + # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | ||
| 4 | + # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
| 5 | + # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| 6 | + # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
| 7 | + # FOR A PARTICULAR PURPOSE. | ||
| 8 | + # =========================================================================== | ||
| 9 | + import unittest | ||
| 10 | + import clr | ||
| 11 | + clr.AddReference('Python.Test') | ||
| 12 | + | ||
| 13 | + from Python.Test import DocWithCtorTest, DocWithoutCtorTest, DocWithCtorNoDocTest | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + class DocStringTests(unittest.TestCase): | ||
| 17 | + """Test doc strings support.""" | ||
| 18 | + | ||
| 19 | + def testDocWithCtor(self): | ||
| 20 | + self.assertEqual(DocWithCtorTest.__doc__, 'DocWithCtorTest Class') | ||
| 21 | + self.assertEqual(DocWithCtorTest.TestMethod.__doc__, 'DocWithCtorTest TestMethod') | ||
| 22 | + self.assertEqual(DocWithCtorTest.StaticTestMethod.__doc__, 'DocWithCtorTest StaticTestMethod') | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + def testDocWithCtorNoDoc(self): | ||
| 26 | + self.assertEqual(DocWithCtorNoDocTest.__doc__, 'Void .ctor(Boolean)') | ||
| 27 | + self.assertEqual(DocWithCtorNoDocTest.TestMethod.__doc__, 'Void TestMethod(Double, Int32)') | ||
| 28 | + self.assertEqual(DocWithCtorNoDocTest.StaticTestMethod.__doc__, 'Void StaticTestMethod(Double, Int32)') | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + def testDocWithoutCtor(self): | ||
| 32 | + self.assertEqual(DocWithoutCtorTest.__doc__, 'DocWithoutCtorTest Class') | ||
| 33 | + self.assertEqual(DocWithoutCtorTest.TestMethod.__doc__, 'DocWithoutCtorTest TestMethod') | ||
| 34 | + self.assertEqual(DocWithoutCtorTest.StaticTestMethod.__doc__, 'DocWithoutCtorTest StaticTestMethod') | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + def test_suite(): | ||
| 38 | + return unittest.makeSuite(DocStringTests) | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + def main(): | ||
| 42 | + unittest.TextTestRunner().run(test_suite()) | ||
| 43 | + | ||
| 44 | + | ||
| 45 | + if __name__ == '__main__': | ||
| 46 | + main() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments