| 1 |  |  | import unittest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | import sys | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | sys.path.insert(0, ".") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | from coalib.bearlib.languages.documentation.DocstyleDefinition import ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |     DocstyleDefinition) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | from coalib.misc.Compatability import FileNotFoundError | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  | class DocstyleDefinitionTest(unittest.TestCase): | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |     def test_fail_instantation(self): | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |         with self.assertRaises(ValueError): | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |             DocstyleDefinition("PYTHON", "doxyGEN", (("##", "#"),)) | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |         with self.assertRaises(ValueError): | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |             DocstyleDefinition("WEIRD-PY", | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |                                "schloxygen", | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |                                (("##+", "x", "y", "z"),)) | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         with self.assertRaises(ValueError): | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |             DocstyleDefinition("PYTHON", | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |                                "doxygen", | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |                                (("##", "", "#"), ('"""', '"""'))) | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     def test_properties(self): | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         uut = DocstyleDefinition("C", "doxygen", (("/**", "*", "*/"),)) | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         self.assertEqual(uut.language, "c") | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         self.assertEqual(uut.docstyle, "doxygen") | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         self.assertEqual(uut.markers, (("/**", "*", "*/"),)) | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         uut = DocstyleDefinition("PYTHON", "doxyGEN", [("##", "", "#")]) | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         self.assertEqual(uut.language, "python") | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         self.assertEqual(uut.docstyle, "doxygen") | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         self.assertEqual(uut.markers, (("##", "", "#"),)) | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         uut = DocstyleDefinition("I2C", | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |                                  "my-custom-tool", | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |                                  (["~~", "/~", "/~"], (">!", ">>", ">>"))) | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         self.assertEqual(uut.language, "i2c") | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         self.assertEqual(uut.docstyle, "my-custom-tool") | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         self.assertEqual(uut.markers, (("~~", "/~", "/~"), (">!", ">>", ">>"))) | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     def test_load(self): | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         # Test unregistered docstyle. | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         with self.assertRaises(FileNotFoundError): | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             next(DocstyleDefinition.load("PYTHON", "INVALID")) | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         # Test unregistered language in existing docstyle. | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         with self.assertRaises(KeyError): | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |             next(DocstyleDefinition.load("bake-a-cake", "default")) | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         # Test python 3 default configuration and if everything is parsed | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         # right. | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         result = DocstyleDefinition.load("PYTHON3", "default") | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         self.assertEqual(result.language, "python3") | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         self.assertEqual(result.docstyle, "default") | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         self.assertEqual(result.markers, (('"""', '', '"""'),)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | if __name__ == '__main__': | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  |     unittest.main(verbosity=2) | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  |