Add litwiki unit test to pre commit hook
This commit is contained in:
parent
6fb703a12e
commit
5131ce5400
|
@ -8,9 +8,7 @@ repos:
|
|||
- id: check-added-large-files
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: pylint
|
||||
name: pylint
|
||||
entry: pylint
|
||||
- id: litwiki-tests
|
||||
name: litwiki-tests
|
||||
entry: ./test.sh
|
||||
language: system
|
||||
types: [python]
|
||||
require_serial: true
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
orgparse = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.11"
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "22f5663e77fd5f550bbb84f958573b3be232bb1211f2944c495839868e6f8553"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.11"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"orgparse": {
|
||||
"hashes": [
|
||||
"sha256:451050e79acb7a51c65dc99b9095eae4d50bd598541354f9e763cb4cbdf59a55",
|
||||
"sha256:f8c8b6c07e8c5a99a27ad3962eedab3aa3844129cbdfd3f2cd32a2197da462fe"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.3.2"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
import unittest
|
||||
from typing import Optional
|
||||
import dataclasses
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Citation:
|
||||
volume: int
|
||||
chapter: int
|
||||
line: int
|
||||
|
||||
|
||||
def parse(src: str) -> Optional[Citation]:
|
||||
try:
|
||||
volume, chapter, line = src.split(".")
|
||||
volume = int(volume)
|
||||
chapter = int(chapter)
|
||||
line = int(line)
|
||||
if volume <= 0 or chapter <= 0 or line <= 0:
|
||||
raise ValueError(f"Invalid citation point {volume}.{chapter}.{line}")
|
||||
return Citation(volume, chapter, line)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
class TestCitation(unittest.TestCase):
|
||||
def test_parse(self):
|
||||
self.assertEqual(parse("1.2.3"), Citation(1, 2, 3))
|
||||
self.assertEqual(parse("1.2.0"), None)
|
||||
self.assertEqual(parse("(I.2.3)"), None)
|
||||
self.assertEqual(parse("I.5.1"), None)
|
||||
self.assertEqual(parse(""), None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in New Issue