Skip to content

Commit

Permalink
Updated travis config -> fixed paths for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
holzkohlengrill committed Sep 18, 2019
1 parent 5954a3c commit a5215b6
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 127 deletions.
62 changes: 31 additions & 31 deletions tests/functional_tests/test__cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
from pypiscout.SCout_Logger import Logger as sc
from matplotlib import pyplot as plt

sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "Emma"))
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))
# pylint: disable=wrong-import-position
# Rationale: This module needs to access modules that are above them in the folder structure.

import emma
import emma_vis
from shared_libs.stringConstants import * # pylint: disable=unused-wildcard-import,wildcard-import
import Emma.emma
import Emma.emma_vis
from Emma.shared_libs.stringConstants import * # pylint: disable=unused-wildcard-import,wildcard-import


class TestHelper(unittest.TestCase):
Expand Down Expand Up @@ -122,8 +122,8 @@ def test_normalRun(self):
Check that an ordinary run is successful
"""
try:
args = emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--dir", self.cmdLineTestOutputFolder])
emma.main(args)
args = Emma.emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--dir", self.cmdLineTestOutputFolder])
Emma.emma.main(args)
except Exception as e: # pylint: disable=broad-except
# Rationale: The purpose here is to catch any exception.
self.fail("Unexpected exception: " + str(e))
Expand All @@ -133,44 +133,44 @@ def test_help(self):
Check that `--help` does not raise an exception but exits with SystemExit(0)
"""
with self.assertRaises(SystemExit) as context:
args = emma.parseArgs(["--help"])
emma.main(args)
args = Emma.emma.parseArgs(["--help"])
Emma.emma.main(args)
self.assertEqual(context.exception.code, 0)

def test_unrecognisedArgs(self):
"""
Check that an unexpected argument does raise an exception
"""
with self.assertRaises(SystemExit) as context:
args = emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--dir", self.cmdLineTestOutputFolder, "--blahhhhhh"])
emma.main(args)
args = Emma.emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--dir", self.cmdLineTestOutputFolder, "--blahhhhhh"])
Emma.emma.main(args)
self.assertEqual(context.exception.code, 2)

def test_noProjDir(self):
"""
Check run with non-existing project folder
"""
with self.assertRaises(SystemExit) as context:
args = emma.parseArgs(["--project", self.nonExistingPath, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--dir", self.cmdLineTestOutputFolder])
emma.main(args)
args = Emma.emma.parseArgs(["--project", self.nonExistingPath, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--dir", self.cmdLineTestOutputFolder])
Emma.emma.main(args)
self.assertEqual(context.exception.code, -10)

def test_noMapfileDir(self):
"""
Check run with non-existing mapfile folder
"""
with self.assertRaises(SystemExit) as context:
args = emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.nonExistingPath, "--dir", self.cmdLineTestOutputFolder])
emma.main(args)
args = Emma.emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.nonExistingPath, "--dir", self.cmdLineTestOutputFolder])
Emma.emma.main(args)
self.assertEqual(context.exception.code, -10)

def test_noDirOption(self):
"""
Check run without a --dir parameter
"""
try:
args = emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder])
emma.main(args)
args = Emma.emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder])
Emma.emma.main(args)
except Exception as e: # pylint: disable=broad-except
# Rationale: The purpose here is to catch any exception.
self.fail("Unexpected exception: " + str(e))
Expand Down Expand Up @@ -198,18 +198,18 @@ def runEmma(self, outputFolder=None):
:return: None
"""
if outputFolder is not None:
args = emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--dir", outputFolder, "--noprompt"])
args = Emma.emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--dir", outputFolder, "--noprompt"])
else:
args = emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--noprompt"])
emma.main(args)
args = Emma.emma.parseArgs(["--project", self.cmdLineTestProjectFolder, "--mapfiles", self.cmdLineTestProjectMapfilesFolder, "--noprompt"])
Emma.emma.main(args)

def test_normalRun(self):
"""
Check that an ordinary run is successful
"""
try:
argsEmmaVis = emma_vis.parseArgs(["--project", self.cmdLineTestProjectFolder, "--overview", "--inOutDir", self.cmdLineTestOutputFolder, "--noprompt", "--quiet"])
emma_vis.main(argsEmmaVis)
argsEmmaVis = Emma.emma_vis.parseArgs(["--project", self.cmdLineTestProjectFolder, "--overview", "--inOutDir", self.cmdLineTestOutputFolder, "--noprompt", "--quiet"])
Emma.emma_vis.main(argsEmmaVis)
except Exception as e: # pylint: disable=broad-except
# Rationale: The purpose here is to catch any exception.
self.fail("Unexpected exception: " + str(e))
Expand All @@ -219,35 +219,35 @@ def test_help(self):
Check that `--help` does not raise an exception but exits with SystemExit(0)
"""
with self.assertRaises(SystemExit) as context:
args = emma_vis.parseArgs(["--help"])
emma_vis.main(args)
args = Emma.emma_vis.parseArgs(["--help"])
Emma.emma_vis.main(args)
self.assertEqual(context.exception.code, 0)

def test_unrecognisedArgs(self):
"""
Check that an unexpected argument does raise an exception
"""
with self.assertRaises(SystemExit) as context:
args = emma_vis.parseArgs(["--project", self.cmdLineTestProjectFolder, "overview", "--dir", self.cmdLineTestOutputFolder, "--blahhhhhh", "--noprompt", "--quiet"])
emma_vis.main(args)
args = Emma.emma_vis.parseArgs(["--project", self.cmdLineTestProjectFolder, "overview", "--dir", self.cmdLineTestOutputFolder, "--blahhhhhh", "--noprompt", "--quiet"])
Emma.emma_vis.main(args)
self.assertEqual(context.exception.code, 2)

def test_noProjDir(self):
"""
Check run with non-existing project folder
"""
with self.assertRaises(SystemExit) as context:
args = emma_vis.parseArgs(["--project", self.nonExistingPath, "--overview", "--inOutDir", self.cmdLineTestOutputFolder, "--noprompt", "--quiet"])
emma_vis.main(args)
args = Emma.emma_vis.parseArgs(["--project", self.nonExistingPath, "--overview", "--inOutDir", self.cmdLineTestOutputFolder, "--noprompt", "--quiet"])
Emma.emma_vis.main(args)
self.assertEqual(context.exception.code, -10)

def test_noMemStats(self):
"""
Check run with non-existing memStats folder
"""
with self.assertRaises(SystemExit) as context:
args = emma_vis.parseArgs(["--project", self.cmdLineTestProjectFolder, "--overview", "--inOutDir", self.nonExistingPath, "--noprompt", "--quiet"])
emma_vis.main(args)
args = Emma.emma_vis.parseArgs(["--project", self.cmdLineTestProjectFolder, "--overview", "--inOutDir", self.nonExistingPath, "--noprompt", "--quiet"])
Emma.emma_vis.main(args)
self.assertEqual(context.exception.code, -10)

def test_noDirOption(self):
Expand All @@ -258,8 +258,8 @@ def test_noDirOption(self):
# This a is a specific case, the default Emma results will not work here. Because of this, we will delete it and run the Emma again.
shutil.rmtree(self.cmdLineTestOutputFolder)
self.runEmma()
args = emma_vis.parseArgs(["--project", self.cmdLineTestProjectFolder, "--overview", "--noprompt", "--quiet"])
emma_vis.main(args)
args = Emma.emma_vis.parseArgs(["--project", self.cmdLineTestProjectFolder, "--overview", "--noprompt", "--quiet"])
Emma.emma_vis.main(args)
plt.close('all')
except Exception as e: # pylint: disable=broad-except
# Rationale: The purpose here is to catch any exception.
Expand Down
10 changes: 5 additions & 5 deletions tests/functional_tests/test__test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import pandas


sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "Emma"))
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))
# pylint: disable=wrong-import-position
# Rationale: This module needs to access modules that are above them in the folder structure.

from shared_libs.stringConstants import * # pylint: disable=unused-wildcard-import,wildcard-import
import emma
from Emma.shared_libs.stringConstants import * # pylint: disable=unused-wildcard-import,wildcard-import
import Emma.emma

class EmmaTestProject(unittest.TestCase):
# pylint: disable=invalid-name
Expand Down Expand Up @@ -65,8 +65,8 @@ def setUp(self):
os.mkdir(self.resultsFolder)

# Running the test_project to create the CSV tables
arguments = emma.parseArgs(["--project", testProjectFolder, "--mapfile", mapfilesFolder, "--dir", self.resultsFolder])
emma.main(arguments)
arguments = Emma.emma.parseArgs(["--project", testProjectFolder, "--mapfile", mapfilesFolder, "--dir", self.resultsFolder])
Emma.emma.main(arguments)

for _, directories, files in os.walk(self.memStatsFolder):
# The result folder shall have 0 subdirectories and three summary files
Expand Down
62 changes: 31 additions & 31 deletions tests/unit_tests/test_emma_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

from pypiscout.SCout_Logger import Logger as sc

sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "Emma"))
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))
# pylint: disable=wrong-import-position
# Rationale: This module needs to access modules that are above them in the folder structure.

from shared_libs.stringConstants import * # pylint: disable=unused-wildcard-import,wildcard-import
import shared_libs.emma_helper
from Emma.shared_libs.stringConstants import * # pylint: disable=unused-wildcard-import,wildcard-import
import Emma.shared_libs.emma_helper


class EmmaHelperTestCase(unittest.TestCase):
Expand All @@ -50,28 +50,28 @@ def setUp(self):

def test_checkIfFolderExists(self):
try:
shared_libs.emma_helper.checkIfFolderExists(os.path.dirname(__file__))
Emma.shared_libs.emma_helper.checkIfFolderExists(os.path.dirname(__file__))
except Exception: # pylint: disable=broad-except
# Rationale: The goal here is to catch any exception types.
self.fail("Unexpected exception!")
with self.assertRaises(SystemExit) as contextManager:
shared_libs.emma_helper.checkIfFolderExists("DefinitelyNonExistingFolder")
Emma.shared_libs.emma_helper.checkIfFolderExists("DefinitelyNonExistingFolder")
self.assertEqual(contextManager.exception.code, "error")

def test_checkIfFileExists(self):
try:
shared_libs.emma_helper.checkIfFileExists(__file__)
Emma.shared_libs.emma_helper.checkIfFileExists(__file__)
except Exception: # pylint: disable=broad-except
# Rationale: The goal here is to catch any exception types.
self.fail("Unexpected exception!")
with self.assertRaises(SystemExit) as contextManager:
shared_libs.emma_helper.checkIfFileExists("DefinitelyNonExisting.file")
Emma.shared_libs.emma_helper.checkIfFileExists("DefinitelyNonExisting.file")
self.assertEqual(contextManager.exception.code, "error")

def test_mkDirIfNeeded(self):
directoryName = "TestDirectoryNameThatShouldNotExist"
self.assertFalse(os.path.isdir(directoryName))
shared_libs.emma_helper.mkDirIfNeeded(directoryName)
Emma.shared_libs.emma_helper.mkDirIfNeeded(directoryName)
self.assertTrue(os.path.isdir(directoryName))
os.rmdir(directoryName)

Expand All @@ -81,10 +81,10 @@ def test_readJsonWriteJson(self):

jsonContentToWrite = {"TestDictionary": {}}
jsonContentToWrite["TestDictionary"]["test_passed"] = True
shared_libs.emma_helper.writeJson(jsonTestFilePath, jsonContentToWrite)
Emma.shared_libs.emma_helper.writeJson(jsonTestFilePath, jsonContentToWrite)
self.assertTrue(os.path.exists(jsonTestFilePath))

jsonContentReadIn = shared_libs.emma_helper.readJson(jsonTestFilePath)
jsonContentReadIn = Emma.shared_libs.emma_helper.readJson(jsonTestFilePath)
self.assertIn("TestDictionary", jsonContentReadIn)
self.assertIn("test_passed", jsonContentReadIn["TestDictionary"])
self.assertEqual(type(jsonContentReadIn["TestDictionary"]["test_passed"]), bool)
Expand All @@ -93,48 +93,48 @@ def test_readJsonWriteJson(self):
self.assertFalse(os.path.exists(jsonTestFilePath))

def test_unifyAddress(self):
hexResult, decResult = shared_libs.emma_helper.unifyAddress("0x16")
hexResult, decResult = Emma.shared_libs.emma_helper.unifyAddress("0x16")
self.assertEqual(hexResult, "0x16")
self.assertEqual(decResult, 22)
hexResult, decResult = shared_libs.emma_helper.unifyAddress(22)
hexResult, decResult = Emma.shared_libs.emma_helper.unifyAddress(22)
self.assertEqual(hexResult, "0x16")
self.assertEqual(decResult, 22)
with self.assertRaises(ValueError) as contextManager:
hexResult, decResult = shared_libs.emma_helper.unifyAddress("Obviously not a number...")
hexResult, decResult = Emma.shared_libs.emma_helper.unifyAddress("Obviously not a number...")
with self.assertRaises(SystemExit) as contextManager:
hexResult, decResult = shared_libs.emma_helper.unifyAddress(0.123)
hexResult, decResult = Emma.shared_libs.emma_helper.unifyAddress(0.123)
self.assertEqual(contextManager.exception.code, "error")

def test_getTimestampFromFilename(self):
timestamp = shared_libs.emma_helper.getTimestampFromFilename("MyFile_2017-11-06-14h56s52.csv")
timestamp = Emma.shared_libs.emma_helper.getTimestampFromFilename("MyFile_2017-11-06-14h56s52.csv")
self.assertEqual(timestamp, "2017-11-06-14h56s52")
with self.assertRaises(SystemExit) as contextManager:
shared_libs.emma_helper.getTimestampFromFilename("MyFileWithoutTimeStamp.csv")
Emma.shared_libs.emma_helper.getTimestampFromFilename("MyFileWithoutTimeStamp.csv")
self.assertEqual(contextManager.exception.code, "error")

def test_toHumanReadable(self):
self.assertEqual(" 0.00 B", shared_libs.emma_helper.toHumanReadable(0))
self.assertEqual(" 10.00 B", shared_libs.emma_helper.toHumanReadable(10))
self.assertEqual(" 1024.00 B", shared_libs.emma_helper.toHumanReadable(1024))
self.assertEqual(" 1.00 KiB", shared_libs.emma_helper.toHumanReadable(1025))
self.assertEqual(" 1.01 KiB", shared_libs.emma_helper.toHumanReadable(1035))
self.assertEqual(" 1.10 KiB", shared_libs.emma_helper.toHumanReadable(1126))
self.assertEqual(" 157.36 GiB", shared_libs.emma_helper.toHumanReadable(168963795964))
self.assertEqual(" 0.00 B", Emma.shared_libs.emma_helper.toHumanReadable(0))
self.assertEqual(" 10.00 B", Emma.shared_libs.emma_helper.toHumanReadable(10))
self.assertEqual(" 1024.00 B", Emma.shared_libs.emma_helper.toHumanReadable(1024))
self.assertEqual(" 1.00 KiB", Emma.shared_libs.emma_helper.toHumanReadable(1025))
self.assertEqual(" 1.01 KiB", Emma.shared_libs.emma_helper.toHumanReadable(1035))
self.assertEqual(" 1.10 KiB", Emma.shared_libs.emma_helper.toHumanReadable(1126))
self.assertEqual(" 157.36 GiB", Emma.shared_libs.emma_helper.toHumanReadable(168963795964))

def test_evalSummary(self):
self.assertEqual(shared_libs.emma_helper.evalSummary("Projectname_" + FILE_IDENTIFIER_SECTION_SUMMARY + "_2017-11-06-14h56s52.csv"), FILE_IDENTIFIER_SECTION_SUMMARY)
self.assertEqual(shared_libs.emma_helper.evalSummary("Projectname_" + FILE_IDENTIFIER_OBJECT_SUMMARY + "_2017-11-06-14h56s52.csv"), FILE_IDENTIFIER_OBJECT_SUMMARY)
self.assertIsNone(shared_libs.emma_helper.evalSummary("Projectname_" + "_2017-11-06-14h56s52.csv"))
self.assertEqual(Emma.shared_libs.emma_helper.evalSummary("Projectname_" + FILE_IDENTIFIER_SECTION_SUMMARY + "_2017-11-06-14h56s52.csv"), FILE_IDENTIFIER_SECTION_SUMMARY)
self.assertEqual(Emma.shared_libs.emma_helper.evalSummary("Projectname_" + FILE_IDENTIFIER_OBJECT_SUMMARY + "_2017-11-06-14h56s52.csv"), FILE_IDENTIFIER_OBJECT_SUMMARY)
self.assertIsNone(Emma.shared_libs.emma_helper.evalSummary("Projectname_" + "_2017-11-06-14h56s52.csv"))

def test_projectNameFromPath(self):
self.assertEqual("MyProject", shared_libs.emma_helper.projectNameFromPath(os.path.join("C:", "GitRepos", "Emma", "MyProject")))
self.assertEqual("MyProject", Emma.shared_libs.emma_helper.projectNameFromPath(os.path.join("C:", "GitRepos", "Emma", "MyProject")))

def test_joinPath(self):
if platform.system() == "Windows":
self.assertEqual(r"c:Documents\Projects\Emma", shared_libs.emma_helper.joinPath("c:", "Documents", "Projects", "Emma"))
self.assertEqual(r"..\..\Emma\tests\other_files", shared_libs.emma_helper.joinPath("..", "..", "Emma", "tests", "other_files"))
self.assertEqual(r"c:Documents\Projects\Emma", Emma.shared_libs.emma_helper.joinPath("c:", "Documents", "Projects", "Emma"))
self.assertEqual(r"..\..\Emma\tests\other_files", Emma.shared_libs.emma_helper.joinPath("..", "..", "Emma", "tests", "other_files"))
elif platform.system() == "Linux":
self.assertEqual(r"Documents/Projects/Emma", shared_libs.emma_helper.joinPath("Documents", "Projects", "Emma"))
self.assertEqual(r"../../Emma/tests/other_files", shared_libs.emma_helper.joinPath("..", "..", "Emma", "tests", "other_files"))
self.assertEqual(r"Documents/Projects/Emma", Emma.shared_libs.emma_helper.joinPath("Documents", "Projects", "Emma"))
self.assertEqual(r"../../Emma/tests/other_files", Emma.shared_libs.emma_helper.joinPath("..", "..", "Emma", "tests", "other_files"))
else:
raise EnvironmentError("Unexpected platform value: " + platform.system())
Loading

0 comments on commit a5215b6

Please sign in to comment.