Skip to content

Commit

Permalink
Use regex substitution and add one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
Charl1996 committed Mar 27, 2024
1 parent 2781e73 commit 6af14f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 3 additions & 5 deletions commcare_export/__init__.py
@@ -1,5 +1,6 @@
import logging
import os
import re
from .version import __version__

repo_root = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir))
Expand All @@ -18,11 +19,8 @@ def write(self, buf):

def logger_name_from_filepath(filepath):
relative_path = os.path.relpath(filepath, start=repo_root)
return (
relative_path.
replace('/', '.').
strip('.py')
)
cleaned_path = relative_path.replace('/', '.')
return re.sub(r'\.py$', '', cleaned_path)


def get_error_logger():
Expand Down
4 changes: 4 additions & 0 deletions tests/test_commcare_export.py
Expand Up @@ -27,3 +27,7 @@ def test_file_contains_py(self):
def test_file_dir_contains_periods(self):
path = self._file_path("sub.dir/pytest.py")
assert logger_name_from_filepath(path) == 'sub.dir.pytest'

def test_random_file_name(self):
path = self._file_path("pyppy.excel_query.py")
assert logger_name_from_filepath(path) == 'pyppy.excel_query'

0 comments on commit 6af14f6

Please sign in to comment.