question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to improve a large snapshot instance and make it more readable

See original GitHub issue

I parsed an XML file and obtained a very large instance which contain many objects and lists. I want to make the parsed instance more readable and testable with snapshot data.

Here are my questions:

  • What’s the best practice to make a snapshot of a large instance?
  • How to make the snapshot file more readable (code highlighting, line breaks)?
  • My IDE (VSCode) doesn’t recognize .ambr file, and will not have code highlighting automatically for that snapshot file. Any solution?

Snapshot Approach 1: stringify self.__dict__

def __repr__(self) -> str:
    return f"{type(self).__name__}({self.__dict__})"

output:

  Context({xml_id': 1234, 'links': [...], ...})  # a very long line

Pro: The type in the format Context({ ... }) would be highlighted with different color using Ruby/Python code highlighter.

Con: The class Context has many list properties and the line of snapshot would be very long (> 10,000 columns). It’s hard to read and compare.

Snapshot Approach 2: JSON serialization

def __repr__(self) -> str:
    return json.dumps(self.__dict__, indent=2)

output:

  {
    "xml_id": 1234, 
    "links": [
      ...
    ], 
    ...
  }

Pro: The line breaks make the large instance more readable.

Con: It’s hard to add types to custom objects like the format Context({ ... }) with json format. I want add the types to object strings and make them distinguished with string values by different highlighting color.

Any suggestion?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iamogbzcommented, May 30, 2021

@xareelee also you can look into the matchers option, which I think can implement these cases without the need for monkey patching, as it allows you to replace the object that will be serialized.

1reaction
xareeleecommented, May 30, 2021

@iamogbz Thanks for the info. I think that it should be documented in docs/ for other users.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create Amazon EBS snapshots - AWS Documentation
Multi-volume snapshots support up to 40 EBS volumes for each instance. To create a snapshot from the volumes of an instance, use one...
Read more >
Amazon EBS and Snapshot Optimization Strategies for Better ...
Many organizations rely on Amazon Elastic Block Store (EBS) to run their business critical application workloads including enterprise ...
Read more >
Best practices for persistent disk snapshots - Google Cloud
As a best practice, take a snapshot of the disk once per hour. Avoid taking snapshots more often than that. The easiest way...
Read more >
AWS Snapshots: Ultimate Intro to Amazon EBS Snapshots
AWS Snapshots for Amazon EBS volumes provide AWS users with a way to create backup copies of the data. Find out the benefits...
Read more >
Performance impact of snapshots in VMware vSphere 7
This is why the provisioned storage size of a VM with snapshots can increase by some huge number and cause problems for your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found