Home > Software engineering >  how to assert a binary multiline value in python using pytest
how to assert a binary multiline value in python using pytest

Time:10-26

I have the following scenario using python3:

type(file_pointer)
=> <class '_io.BytesIO'>

then


file_pointer.get_value()

# result below

b'simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.'

what is the good way of asserting the above with python and pytest based on the fact its a multiline

I have tried:

assert file_pointer == (
  'b'simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the' 
  'industry's standard dummy text ever since the 1500s, when an unknown printer took a' 
  'galley of type and scrambled it to make a type specimen book. It has survived not only' 
  'five centuries, but also the leap into electronic typesetting, remaining essentially' 
  'unchanged. It was popularised in the 1960s with the release of Letraset sheets'
  'containing Lorem Ipsum passages, and more recently with desktop publishing software' 
  'like Aldus PageMaker including versions of Lorem Ipsum.''
)

and it does not seem to work

Any help would be helpful thanks in advance.

CodePudding user response:

Use triple quotes. The original one-line assignment was breaking where the word industry's had an apostrophe in it.

assert file_pointer.get_value() == (
  b"""simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.""")
  • Related