Skip to content

Commit

Permalink
Python 2.7 'u' strings fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarvalus committed Sep 11, 2018
1 parent e8c91e8 commit 78c78ec
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/test_tinydb.py
@@ -1,5 +1,6 @@
# coding=utf-8
import sys
import re

import pytest

Expand Down Expand Up @@ -692,6 +693,7 @@ def _get_doc_id(self, document):
def test_repr(tmpdir):
path = str(tmpdir.join('db.json'))

assert repr(TinyDB(path)) ==\
"<TinyDB tables=['_default'], tables_count=1, " +\
"default_table_documents_count=0, all_tables_documents_count=['_default=0']>"
assert bool(re.match(
r"\<TinyDB tables\=\[u?\'\_default\'\]\, tables\_count\=1\, " +
"default\_table\_documents\_count\=0\, all\_tables\_documents\_count\=\[\'\_default\=0\'\]\>",
repr(TinyDB(path)))) is True

1 comment on commit 78c78ec

@cool-RR
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea using a regex. A few improvements:

  1. You can remove the casting to bool and the is True. You can just do assert re.match(pattern, repr(TinyDB(path))) and Python will deal with it :)
  2. You're escaping too many characters in your regular expression, making it harder to read. There's no need to escape these characters: _=,><
  3. Don't use + to add string literals. You can just put two string literals one after another and Python will add them up for you by default. So just remove the plus sign and you're good.

Good job!

Please sign in to comment.