Skip to content

Commit

Permalink
test: refer to test data path via variable (HelloZeroNet#1964)
Browse files Browse the repository at this point in the history
  • Loading branch information
radfish authored and HelloZeroNet committed Apr 10, 2019
1 parent ed12cc1 commit 6a1d716
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/Test/TestSite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import pytest
from Site import SiteManager

TEST_DATA_PATH = "src/Test/testdata"

@pytest.mark.usefixtures("resetSettings")
class TestSite:
def testClone(self, site):
assert site.storage.directory == "src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
assert site.storage.directory == TEST_DATA_PATH + "/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"

# Remove old files
if os.path.isdir("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL"):
shutil.rmtree("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
assert not os.path.isfile("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL/content.json")
if os.path.isdir(TEST_DATA_PATH + "/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL"):
shutil.rmtree(TEST_DATA_PATH + "/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
assert not os.path.isfile(TEST_DATA_PATH + "/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL/content.json")

# Clone 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT to 15E5rhcAUD69WbiYsYARh4YHJ4sLm2JEyc
new_site = site.clone(
Expand Down Expand Up @@ -61,7 +62,7 @@ def testClone(self, site):

# Delete created files
new_site.storage.deleteFiles()
assert not os.path.isdir("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
assert not os.path.isdir(TEST_DATA_PATH + "/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")

# Delete from site registry
assert new_site.address in SiteManager.site_manager.sites
Expand Down
5 changes: 3 additions & 2 deletions src/Test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def filter(self, record):
# Load plugins
from Plugin import PluginManager

config.data_dir = "src/Test/testdata" # Use test data for unittests
TEST_DATA_PATH = 'src/Test/testdata'
config.data_dir = TEST_DATA_PATH # Use test data for unittests

os.chdir(os.path.abspath(os.path.dirname(__file__) + "/../..")) # Set working dir

Expand All @@ -85,7 +86,7 @@ def filter(self, record):
config.verbose = True # Use test data for unittests
config.tor = "disable" # Don't start Tor client
config.trackers = []
config.data_dir = "src/Test/testdata" # Use test data for unittests
config.data_dir = TEST_DATA_PATH # Use test data for unittests
config.initLogging()

from Site import Site
Expand Down

0 comments on commit 6a1d716

Please sign in to comment.