mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-25 15:00:27 -04:00
Revert "Try and move local tests into main tests dir. Rename local tests. Save test settings to unique json files to avoid race conditions"
This reverts commit 43eda6b9df
.
This commit is contained in:
parent
43eda6b9df
commit
418252f7c6
13 changed files with 181 additions and 14 deletions
|
@ -19,4 +19,5 @@ before_script:
|
||||||
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||||
# run CLI tests and local GUI tests
|
# run CLI tests and local GUI tests
|
||||||
script:
|
script:
|
||||||
- xvfb-run pytest --cov=onionshare tests/
|
- pytest --cov=onionshare tests/
|
||||||
|
- cd tests_gui_local/ && xvfb-run ./run_unit_tests.sh
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
from .GuiBaseTest import GuiBaseTest
|
|
|
@ -20,7 +20,7 @@ from onionshare_gui.mode.receive_mode import ReceiveMode
|
||||||
|
|
||||||
class GuiBaseTest(object):
|
class GuiBaseTest(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_up(test_settings, settings_filename='/tmp/testsettings.json'):
|
def set_up(test_settings):
|
||||||
'''Create GUI with given settings'''
|
'''Create GUI with given settings'''
|
||||||
# Create our test file
|
# Create our test file
|
||||||
testfile = open('/tmp/test.txt', 'w')
|
testfile = open('/tmp/test.txt', 'w')
|
||||||
|
@ -45,6 +45,7 @@ class GuiBaseTest(object):
|
||||||
app = OnionShare(common, testonion, True, 0)
|
app = OnionShare(common, testonion, True, 0)
|
||||||
|
|
||||||
web = Web(common, False, True)
|
web = Web(common, False, True)
|
||||||
|
settings_filename = '/tmp/testsettings.json'
|
||||||
open(settings_filename, 'w').write(json.dumps(test_settings))
|
open(settings_filename, 'w').write(json.dumps(test_settings))
|
||||||
|
|
||||||
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True)
|
gui = OnionShareGui(common, testonion, qtapp, app, ['/tmp/test.txt'], settings_filename, True)
|
1
tests_gui_local/__init__.py
Normal file
1
tests_gui_local/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from .GuiBaseTest import GuiBaseTest
|
160
tests_gui_local/conftest.py
Normal file
160
tests_gui_local/conftest.py
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
import sys
|
||||||
|
# Force tests to look for resources in the source code tree
|
||||||
|
sys.onionshare_dev_mode = True
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from onionshare import common, web, settings
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def temp_dir_1024():
|
||||||
|
""" Create a temporary directory that has a single file of a
|
||||||
|
particular size (1024 bytes).
|
||||||
|
"""
|
||||||
|
|
||||||
|
tmp_dir = tempfile.mkdtemp()
|
||||||
|
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
|
||||||
|
with open(tmp_file, 'wb') as f:
|
||||||
|
f.write(b'*' * 1024)
|
||||||
|
return tmp_dir
|
||||||
|
|
||||||
|
|
||||||
|
# pytest > 2.9 only needs @pytest.fixture
|
||||||
|
@pytest.yield_fixture
|
||||||
|
def temp_dir_1024_delete():
|
||||||
|
""" Create a temporary directory that has a single file of a
|
||||||
|
particular size (1024 bytes). The temporary directory (including
|
||||||
|
the file inside) will be deleted after fixture usage.
|
||||||
|
"""
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
tmp_file, tmp_file_path = tempfile.mkstemp(dir=tmp_dir)
|
||||||
|
with open(tmp_file, 'wb') as f:
|
||||||
|
f.write(b'*' * 1024)
|
||||||
|
yield tmp_dir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def temp_file_1024():
|
||||||
|
""" Create a temporary file of a particular size (1024 bytes). """
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
||||||
|
tmp_file.write(b'*' * 1024)
|
||||||
|
return tmp_file.name
|
||||||
|
|
||||||
|
|
||||||
|
# pytest > 2.9 only needs @pytest.fixture
|
||||||
|
@pytest.yield_fixture
|
||||||
|
def temp_file_1024_delete():
|
||||||
|
"""
|
||||||
|
Create a temporary file of a particular size (1024 bytes).
|
||||||
|
The temporary file will be deleted after fixture usage.
|
||||||
|
"""
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile() as tmp_file:
|
||||||
|
tmp_file.write(b'*' * 1024)
|
||||||
|
tmp_file.flush()
|
||||||
|
yield tmp_file.name
|
||||||
|
|
||||||
|
|
||||||
|
# pytest > 2.9 only needs @pytest.fixture
|
||||||
|
@pytest.yield_fixture(scope='session')
|
||||||
|
def custom_zw():
|
||||||
|
zw = web.share_mode.ZipWriter(
|
||||||
|
common.Common(),
|
||||||
|
zip_filename=common.Common.random_string(4, 6),
|
||||||
|
processed_size_callback=lambda _: 'custom_callback'
|
||||||
|
)
|
||||||
|
yield zw
|
||||||
|
zw.close()
|
||||||
|
os.remove(zw.zip_filename)
|
||||||
|
|
||||||
|
|
||||||
|
# pytest > 2.9 only needs @pytest.fixture
|
||||||
|
@pytest.yield_fixture(scope='session')
|
||||||
|
def default_zw():
|
||||||
|
zw = web.share_mode.ZipWriter(common.Common())
|
||||||
|
yield zw
|
||||||
|
zw.close()
|
||||||
|
tmp_dir = os.path.dirname(zw.zip_filename)
|
||||||
|
shutil.rmtree(tmp_dir)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def locale_en(monkeypatch):
|
||||||
|
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('en_US', 'UTF-8'))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def locale_fr(monkeypatch):
|
||||||
|
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('fr_FR', 'UTF-8'))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def locale_invalid(monkeypatch):
|
||||||
|
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('xx_XX', 'UTF-8'))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def locale_ru(monkeypatch):
|
||||||
|
monkeypatch.setattr('locale.getdefaultlocale', lambda: ('ru_RU', 'UTF-8'))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def platform_darwin(monkeypatch):
|
||||||
|
monkeypatch.setattr('platform.system', lambda: 'Darwin')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture # (scope="session")
|
||||||
|
def platform_linux(monkeypatch):
|
||||||
|
monkeypatch.setattr('platform.system', lambda: 'Linux')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def platform_windows(monkeypatch):
|
||||||
|
monkeypatch.setattr('platform.system', lambda: 'Windows')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sys_argv_sys_prefix(monkeypatch):
|
||||||
|
monkeypatch.setattr('sys.argv', [sys.prefix])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sys_frozen(monkeypatch):
|
||||||
|
monkeypatch.setattr('sys.frozen', True, raising=False)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sys_meipass(monkeypatch):
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'sys._MEIPASS', os.path.expanduser('~'), raising=False)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture # (scope="session")
|
||||||
|
def sys_onionshare_dev_mode(monkeypatch):
|
||||||
|
monkeypatch.setattr('sys.onionshare_dev_mode', True, raising=False)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def time_time_100(monkeypatch):
|
||||||
|
monkeypatch.setattr('time.time', lambda: 100)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def time_strftime(monkeypatch):
|
||||||
|
monkeypatch.setattr('time.strftime', lambda _: 'Jun 06 2013 11:05:00')
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def common_obj():
|
||||||
|
return common.Common()
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def settings_obj(sys_onionshare_dev_mode, platform_linux):
|
||||||
|
_common = common.Common()
|
||||||
|
_common.version = 'DUMMY_VERSION_1.2.3'
|
||||||
|
return settings.Settings(_common)
|
|
@ -20,7 +20,7 @@ class ReceiveModeTest(unittest.TestCase):
|
||||||
test_settings = {
|
test_settings = {
|
||||||
"receive_allow_receiver_shutdown": True
|
"receive_allow_receiver_shutdown": True
|
||||||
}
|
}
|
||||||
cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ReceiveModeTest.json')
|
cls.gui = GuiBaseTest.set_up(test_settings)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
|
@ -21,7 +21,7 @@ class ReceiveModePublicModeTest(unittest.TestCase):
|
||||||
"public_mode": True,
|
"public_mode": True,
|
||||||
"receive_allow_receiver_shutdown": True
|
"receive_allow_receiver_shutdown": True
|
||||||
}
|
}
|
||||||
cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ReceiveModePublicModeTest.json')
|
cls.gui = GuiBaseTest.set_up(test_settings)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
|
@ -19,7 +19,7 @@ class ShareModeTest(unittest.TestCase):
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
test_settings = {
|
test_settings = {
|
||||||
}
|
}
|
||||||
cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeTest.json')
|
cls.gui = GuiBaseTest.set_up(test_settings)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
|
@ -20,7 +20,7 @@ class ShareModePublicModeTest(unittest.TestCase):
|
||||||
test_settings = {
|
test_settings = {
|
||||||
"public_mode": True,
|
"public_mode": True,
|
||||||
}
|
}
|
||||||
cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModePublicModeTest.json')
|
cls.gui = GuiBaseTest.set_up(test_settings)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
|
@ -20,7 +20,7 @@ class ShareModeStayOpenTest(unittest.TestCase):
|
||||||
test_settings = {
|
test_settings = {
|
||||||
"close_after_first_download": False,
|
"close_after_first_download": False,
|
||||||
}
|
}
|
||||||
cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeStayOpenTest.json')
|
cls.gui = GuiBaseTest.set_up(test_settings)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
|
@ -23,23 +23,23 @@ class ShareModePersistentSlugTest(unittest.TestCase):
|
||||||
"save_private_key": True,
|
"save_private_key": True,
|
||||||
"close_after_first_download": False,
|
"close_after_first_download": False,
|
||||||
}
|
}
|
||||||
cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModePersistentSlugTest.json')
|
cls.gui = GuiBaseTest.set_up(test_settings)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
GuiBaseTest.tear_down()
|
GuiBaseTest.tear_down()
|
||||||
|
|
||||||
@pytest.mark.run(order=1000)
|
@pytest.mark.run(order=1)
|
||||||
def test_run_all_common_setup_tests(self):
|
def test_run_all_common_setup_tests(self):
|
||||||
GuiBaseTest.run_all_common_setup_tests(self)
|
GuiBaseTest.run_all_common_setup_tests(self)
|
||||||
|
|
||||||
@pytest.mark.run(order=1001)
|
@pytest.mark.run(order=2)
|
||||||
def test_run_all_persistent_share_mode_tests(self):
|
def test_run_all_share_mode_tests(self):
|
||||||
GuiBaseTest.run_all_share_mode_tests(self, False, True)
|
GuiBaseTest.run_all_share_mode_tests(self, False, True)
|
||||||
global slug
|
global slug
|
||||||
slug = self.gui.share_mode.server_status.web.slug
|
slug = self.gui.share_mode.server_status.web.slug
|
||||||
|
|
||||||
@pytest.mark.run(order=1002)
|
@pytest.mark.run(order=3)
|
||||||
def test_have_same_slug(self):
|
def test_have_same_slug(self):
|
||||||
'''Test that we have the same slug'''
|
'''Test that we have the same slug'''
|
||||||
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
|
self.assertEqual(self.gui.share_mode.server_status.web.slug, slug)
|
|
@ -21,7 +21,7 @@ class ShareModeTimerTest(unittest.TestCase):
|
||||||
"public_mode": False,
|
"public_mode": False,
|
||||||
"shutdown_timeout": True,
|
"shutdown_timeout": True,
|
||||||
}
|
}
|
||||||
cls.gui = GuiBaseTest.set_up(test_settings, '/tmp/ShareModeTimerTest.json')
|
cls.gui = GuiBaseTest.set_up(test_settings)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
5
tests_gui_local/run_unit_tests.sh
Executable file
5
tests_gui_local/run_unit_tests.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for test in `ls -1 | egrep ^onionshare_`; do
|
||||||
|
pytest $test -vvv || exit 1
|
||||||
|
done
|
Loading…
Add table
Add a link
Reference in a new issue