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.

Fails the test because of the quote style.

See original GitHub issue

I have simple wrapper function to the US census library:

def state_info(state):
    """
    Given a the full name of a state, returns the corresponding abbreviation and FIPS code.

    Example:

    >>> state_info("texas")
    ("TX", "48")
    """
    abbrev = states.mapping("name", "abbr").get(state.title())
    st = states.lookup(abbrev)
    fips = st.fips
    return (abbrev, fips)

However xdoctest fails because the of quoting style:

DOCTEST PART BREAKDOWN
Failed Part:
    2 >>> state_info("texas")
DOCTEST TRACEBACK
Expected:
    ("TX", "48")
Got:
    ('TX', '48')
Repr Difference:
    got  = "('TX', '48')"
    want = '("TX", "48")'

Since the expected value matches my output, I thought the test would pass.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Erotemiccommented, Jul 25, 2022

FWIW, the style of the expected “want” string isn’t enforced by black, and it would be more accurate to use the quoting style there that the actual Python interpreter outputs. Also, there is nothing stopping you from simply writing:

def state_info(state):
    """
    Given a the full name of a state, returns the corresponding abbreviation and FIPS code.

    Example:

    >>> assert state_info("texas") == ("TX", "48")
    """
    abbrev = states.mapping("name", "abbr").get(state.title())
    st = states.lookup(abbrev)
    fips = st.fips
    return (abbrev, fips)

And that has the advantage that it can be refactored as a unit test verbatim. The other alternative - if you simply want this for more documentation purposes, is to remove the check entirely and rely on unit tests to actually check cases:

def state_info(state):
    """
    Given a the full name of a state, returns the corresponding abbreviation and FIPS code.

    Example:

    >>> state_info("texas")  # xdoctest: +IGNORE_WANT
    ("TX", "48")
    """
    abbrev = states.mapping("name", "abbr").get(state.title())
    st = states.lookup(abbrev)
    fips = st.fips
    return (abbrev, fips)

But if you want to extend the checker, all of the logic lives here:

https://github.com/Erotemic/xdoctest/blob/main/src/xdoctest/checker.py

It probably also makes sense to add a directive:

https://github.com/Erotemic/xdoctest/blob/main/src/xdoctest/directive.py

which is disabled by default (maybe call it NORMALIZE_QUOTES?) and can be specified to enable this behavior.

0reactions
rgreinhocommented, Jul 25, 2022

Thank you very much! I did use the first alternative you suggested and it worked like a charm. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uplifting Quotes For Those Who Failed the Bar Exam
If you failed the bar exam, we feel for you! ... We believe something as simple as a quote can reveal how important...
Read more >
Quotation Marks and Direct Quotations - University of Sussex
The use of quotation marks, also called inverted commas, is very slightly complicated by the fact that there are two types: single quotes...
Read more >
You Can Quote Me on This - APA Style 6th Edition Blog
Formatting the quotation is more than just an arbitrary means of ensuring consistency. It serves as a flag to the readers, telling them...
Read more >
Titles of Books, Plays, Articles, etc.: Underline? Italics ...
Names of websites are not generally italicized or enclosed in quotation marks, because they are usually made into Internet links that result in...
Read more >
What should I do with a quote found by the check? - Scribbr
If the quote contains 40 words or more, format it as a block quote, which begins on a new line and is indented...
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