Horrible, nasty hack

This commit is contained in:
Hugo Osvaldo Barrera 2020-11-16 19:27:39 +01:00
parent 9df587df26
commit 53878f001a
2 changed files with 36 additions and 29 deletions

View file

@ -2,4 +2,3 @@ hypothesis>=5.0.0
pytest pytest
pytest-cov pytest-cov
pytest-localserver pytest-localserver
pytest-subtesthack

View file

@ -271,6 +271,9 @@ def test_multiple_pairs(tmpdir, runner):
} }
hack = 0
# XXX: https://github.com/pimutils/vdirsyncer/issues/617 # XXX: https://github.com/pimutils/vdirsyncer/issues/617
@pytest.mark.skipif(sys.platform == 'darwin', @pytest.mark.skipif(sys.platform == 'darwin',
reason='This test inexplicably fails') reason='This test inexplicably fails')
@ -291,40 +294,45 @@ def test_multiple_pairs(tmpdir, runner):
@example(collections=['persönlich']) @example(collections=['persönlich'])
@example(collections={'a', 'A'}) @example(collections={'a', 'A'})
@example(collections={'\ufffe'}) @example(collections={'\ufffe'})
def test_create_collections(subtest, collections): def test_create_collections(collections, tmpdir, runner):
# Hypothesis calls this tests in a way that fixtures are not reset, to tmpdir is the
# same for each call.
# This horrible hack creates a new subdirectory on each run, effectively giving us a
# new tmpdir each run.
global hack
hack += 1
tmpdir = tmpdir / f"sub{hack}"
@subtest runner.write_with_general(dedent('''
def test_inner(tmpdir, runner): [pair foobar]
runner.write_with_general(dedent(''' a = "foo"
[pair foobar] b = "bar"
a = "foo" collections = {colls}
b = "bar"
collections = {colls}
[storage foo] [storage foo]
type = "filesystem" type = "filesystem"
path = "{base}/foo/" path = "{base}/foo/"
fileext = ".txt" fileext = ".txt"
[storage bar] [storage bar]
type = "filesystem" type = "filesystem"
path = "{base}/bar/" path = "{base}/bar/"
fileext = ".txt" fileext = ".txt"
'''.format(base=str(tmpdir), colls=json.dumps(list(collections))))) '''.format(base=str(tmpdir), colls=json.dumps(list(collections)))))
result = runner.invoke( result = runner.invoke(
['discover'], ['discover'],
input='y\n' * 2 * (len(collections) + 1) input='y\n' * 2 * (len(collections) + 1)
) )
assert not result.exception, result.output assert not result.exception, result.output
result = runner.invoke( result = runner.invoke(
['sync'] + ['foobar/' + x for x in collections] ['sync'] + ['foobar/' + x for x in collections]
) )
assert not result.exception, result.output assert not result.exception, result.output
assert {x.basename for x in tmpdir.join('foo').listdir()} == \ assert {x.basename for x in tmpdir.join('foo').listdir()} == \
{x.basename for x in tmpdir.join('bar').listdir()} {x.basename for x in tmpdir.join('bar').listdir()}
def test_ident_conflict(tmpdir, runner): def test_ident_conflict(tmpdir, runner):