Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Created August 2, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinThoma/6b6126f767e0245aa581fde80d411ab4 to your computer and use it in GitHub Desktop.
Save MartinThoma/6b6126f767e0245aa581fde80d411ab4 to your computer and use it in GitHub Desktop.
from typing import Dict, Optional
from dataclasses import dataclass
from hypothesis import strategies as st
@dataclass
class PdfInfo:
path: str
is_errornous: bool
is_encrypted: bool
nb_pages: int
nb_toc_top_level: int
nb_characters: int
user_attributes: Dict[str, Optional[str]]
# Usage in test to generate one PdfInfo:
# @given(st.builds(PdfInfo))
# Now show some samples:
for _ in range(10):
print(st.builds(PdfInfo).example())
##########
# Output #
##########
# PdfInfo(path='', is_errornous=False, is_encrypted=True,
# nb_pages=0, nb_toc_top_level=0, nb_characters=0, user_attributes={})
# PdfInfo(path='', is_errornous=False, is_encrypted=True,
# nb_pages=-6679854645310868666, nb_toc_top_level=20135,
# nb_characters=-32,
# user_attributes={'\x02\x15\U0001189c¤\U000e7fde^¹': None})
# PdfInfo(path='', is_errornous=False, is_encrypted=False,
# nb_pages=0, nb_toc_top_level=0, nb_characters=0, user_attributes={})
# PdfInfo(path='', is_errornous=True, is_encrypted=True,
# nb_pages=0, nb_toc_top_level=0, nb_characters=0, user_attributes={})
# PdfInfo(path='', is_errornous=True, is_encrypted=False,
# nb_pages=0, nb_toc_top_level=0, nb_characters=0, user_attributes={})
# PdfInfo(path='¬´à', is_errornous=True, is_encrypted=False,
# nb_pages=-17389, nb_toc_top_level=15767, nb_characters=124,
# user_attributes={})
# PdfInfo(path='', is_errornous=True, is_encrypted=False,
# nb_pages=0, nb_toc_top_level=0, nb_characters=0, user_attributes={})
# PdfInfo(path='', is_errornous=False, is_encrypted=False,
# nb_pages=0, nb_toc_top_level=0, nb_characters=0, user_attributes={})
# PdfInfo(path='', is_errornous=False, is_encrypted=True,
# nb_pages=0, nb_toc_top_level=0, nb_characters=0, user_attributes={})
# PdfInfo(path='', is_errornous=False, is_encrypted=False,
# nb_pages=0, nb_toc_top_level=0, nb_characters=0, user_attributes={})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment