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.

Make term-img easier to unit test

See original GitHub issue

Is your feature request related to a problem? Please describe.

I’m having trouble actually using term-img when running unit tests, because term_img.exceptions.InvalidSize is raised when TermImage is initialized.

Describe the solution you’d like

I’m not sure what’s best here, but one quick solution would be add check_width and check_height args to TermImage, so that they can be passed to set_size here

https://github.com/AnonymouX47/term-img/blob/44182ee63d0f0da281c9c57313e81dca1f3abc14/term_img/image.py#L91

Overall, I’m also wondering if the size shouldn’t be validated at __init__? Might be more appropriate to evaluate at draw() time only.

Describe alternatives you’ve considered

I could just mock get_terminal_size to give me the size I’m trying to emulate in my tests as a fallback, but wondering if the library itself could use some way to control this.

Additional context

Just wanted to say that I’ve really enjoyed using this library, and want to make it the default image renderer in a cli I’m working on. Appreciate the work here!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
paw-lucommented, Mar 7, 2022

I guess they might be be useful for your project.

You’d be right.

Really looking forward to seeing this developing. Will be following closely. Of course, no rush! Really happy already with how the renders turned out.

you can control the alignment (amongst other things)

Yeah I saw that! I don’t see this leveraged a lot so I thought this was an interesting API design!

1reaction
AnonymouX47commented, Mar 7, 2022

I noticed you’re using str(block_image), you can control the alignment (amongst other things) using any string formatting method with the TermImage instance e.g

f"{block_image:{max_width}.{max_height}}"

to always have the images centered within the available space i.e (max_width, max_height).

See here for more.

Read more comments on GitHub >

github_iconTop Results From Across the Web

13 Tips for Writing Useful Unit Tests | by Nick Hodges
1. Test One Thing at a Time in Isolation · 2. Follow the AAA Rule: Arrange, Act, Assert · 3. Write Simple “Fastball-Down-the-Middle”...
Read more >
Taming Android Unit Test when using different flavors and ...
This is the easiest way to create different apps while using the ... Taming Android Unit Test when using different flavors and build...
Read more >
Unit testing cloud products that are not test-friendly... - LinkedIn
Some products needs deployment for unit testing, a simple build pipeline ... Taming the tests - Unit testing cloud products that are not ......
Read more >
Taming the Beast (a.k.a. how to test AJAX applications) : Part 2
All we need to do is implement a mock-RPC-Backend and run that instead. You might want to consider running the mock-RPC-Backend on the...
Read more >
Unit Testing Myths and Practices - Simple Talk
We all understand the value of Unit Testing, but how come so few organisations maintain unit tests for their in-house applications?
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