core/ci: fix windows-specific issues

- use portable separators
- paths should be prepended with r' (so backwards slash isn't treated as escaping)
- sqlite connections should be closed (otherwise windows fails to remove the underlying db file)
- workaround for emojis via PYTHONUTF8=1 test for now
- make ZipPath portable
- properly use tox python environment everywhere

  this was causing issues on Windows
  e.g.
      WARNING: test command found but not installed in testenv
        cmd: C:\hostedtoolcache\windows\Python\3.9.12\x64\python3.EXE
This commit is contained in:
Dima Gerasimov 2022-05-02 18:26:22 +01:00 committed by karlicoss
parent 637982a5ba
commit 64a4782f0e
11 changed files with 67 additions and 37 deletions

View file

@ -1,4 +1,14 @@
import os
from subprocess import check_call
def test_lists_modules() -> None:
check_call(['hpi', 'modules'])
# hack PYTHONUTF8 for windows
# see https://github.com/karlicoss/promnesia/issues/274
# https://memex.zulipchat.com/#narrow/stream/279600-promnesia/topic/indexing.3A.20utf8.28emoji.29.20filenames.20in.20Windows
# necessary for this test cause emooji is causing trouble
# TODO need to fix it properly
env = {
**os.environ,
'PYTHONUTF8': '1',
}
check_call(['hpi', 'modules'], env=env)

View file

@ -1,9 +1,14 @@
# TODO need fdfind on CI?
from pathlib import Path
from more_itertools import bucket
import pytest
import os
pytestmark = pytest.mark.skipif(
os.name == 'nt',
reason='TODO figure out how to install fd-find on Windows',
)
def test() -> None:
from my.coding.commits import commits

View file

@ -76,24 +76,25 @@ def test_zippath() -> None:
hash(zp)
assert zp.exists()
assert (zp / 'gdpr_export/comments').exists()
assert (zp / 'gdpr_export' / 'comments').exists()
# check str constructor just in case
assert (ZipPath(str(target)) / 'gdpr_export/comments').exists()
assert (ZipPath(str(target)) / 'gdpr_export' / 'comments').exists()
assert not (ZipPath(str(target)) / 'whatever').exists()
matched = list(zp.rglob('*'))
assert len(matched) > 0
assert all(p.filepath == target for p in matched), matched
rpaths = [str(p.relative_to(zp)) for p in matched]
rpaths = [p.relative_to(zp) for p in matched]
gdpr_export = Path('gdpr_export')
assert rpaths == [
'gdpr_export',
'gdpr_export/comments',
'gdpr_export/comments/comments.json',
'gdpr_export/profile',
'gdpr_export/profile/settings.json',
'gdpr_export/messages',
'gdpr_export/messages/index.csv',
gdpr_export,
gdpr_export / 'comments',
gdpr_export / 'comments' / 'comments.json',
gdpr_export / 'profile',
gdpr_export / 'profile' / 'settings.json',
gdpr_export / 'messages',
gdpr_export / 'messages' / 'index.csv',
], rpaths
@ -103,14 +104,15 @@ def test_zippath() -> None:
# same for this one
# assert ZipPath(Path('test'), 'whatever').absolute() == ZipPath(Path('test').absolute(), 'whatever')
assert (ZipPath(target) / 'gdpr_export/comments').exists()
assert (ZipPath(target) / 'gdpr_export' / 'comments').exists()
jsons = [str(p.relative_to(zp / 'gdpr_export')) for p in zp.rglob('*.json')]
jsons = [p.relative_to(zp / 'gdpr_export') for p in zp.rglob('*.json')]
assert jsons == [
'comments/comments.json',
'profile/settings.json',
Path('comments','comments.json'),
Path('profile','settings.json'),
]
# NOTE: hmm interesting, seems that ZipPath is happy with forward slash regardless OS?
assert list(zp.rglob('mes*')) == [ZipPath(target, 'gdpr_export/messages')]
iterdir_res = list((zp / 'gdpr_export').iterdir())
@ -118,7 +120,7 @@ def test_zippath() -> None:
assert all(isinstance(p, Path) for p in iterdir_res)
# date recorded in the zip archive
assert (zp / 'gdpr_export/comments/comments.json').stat().st_mtime > 1625000000
assert (zp / 'gdpr_export' / 'comments' / 'comments.json').stat().st_mtime > 1625000000
# TODO ugh.
# unzip -l shows the date as 2021-07-01 09:43
# however, python reads it as 2021-07-01 01:43 ??

View file

@ -43,20 +43,24 @@ def _test_do_copy(db: Path) -> None:
shutil.copy(db, cdb)
with sqlite3.connect(str(cdb)) as conn_copy:
assert len(list(conn_copy.execute('SELECT * FROM testtable'))) == 5
conn_copy.close()
def _test_do_immutable(db: Path) -> None:
# in readonly mode doesn't touch
with sqlite_connect_immutable(db) as conn_imm:
assert len(list(conn_imm.execute('SELECT * FROM testtable'))) == 5
conn_imm.close()
def _test_do_copy_and_open(db: Path) -> None:
with sqlite_copy_and_open(db) as conn_mem:
assert len(list(conn_mem.execute('SELECT * FROM testtable'))) == 10
conn_mem.close()
def _test_open_asis(db: Path) -> None:
# NOTE: this also works... but leaves some potential for DB corruption
with sqlite3.connect(str(db)) as conn_db_2:
assert len(list(conn_db_2.execute('SELECT * FROM testtable'))) == 10
conn_db_2.close()