From bc77938b9ff03b11e1d63650a08f661da1279c39 Mon Sep 17 00:00:00 2001 From: danmosemsft Date: Mon, 31 Aug 2015 20:55:31 -0700 Subject: [PATCH] Fix is_valid() and add tests --- projectsystem/Sourcemap.py | 2 +- tests/SourcemapTests.py | 13 ++++++++++--- tests/TestRunner.py | 2 ++ tests/assets/randomjson.js | 4 ++++ tests/assets/randomjson.js.map | 3 +++ tests/runtests.sh | 3 +++ 6 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/assets/randomjson.js create mode 100644 tests/assets/randomjson.js.map diff --git a/projectsystem/Sourcemap.py b/projectsystem/Sourcemap.py index 07fd694..9edadc1 100644 --- a/projectsystem/Sourcemap.py +++ b/projectsystem/Sourcemap.py @@ -38,7 +38,7 @@ def __init__(self, file_name): pass def is_valid(self): - return not self.content is None + return not self.content is None and not self.authored_sources is None and not self.line_mappings is None def get_authored_sources_path(self): return [os.path.abspath(self.root_path + os.path.sep + x).lower() for x in self.authored_sources] if self.is_valid() else [] diff --git a/tests/SourcemapTests.py b/tests/SourcemapTests.py index 5f6dc45..b81e895 100644 --- a/tests/SourcemapTests.py +++ b/tests/SourcemapTests.py @@ -23,8 +23,8 @@ def test_nonexistent_file_does_not_throw(self): file_name = Sourcemap.get_sourcemap_file("NotExistentFile") self.assertFalse(file_name) - def test_invalid_file_does_not_throw(self): - file_name = Sourcemap.get_sourcemap_file("app.js") # exists, but not valid map file + def test_valid_json_invalid_map_does_not_throw(self): + file_name = Sourcemap.get_sourcemap_file("randomjson.js") # exists, but not valid map file self.assertFalse(file_name) def test_version_check(self): @@ -42,19 +42,26 @@ def test_line_mapping_count(self): class ParsedSourceMapTests(unittest.TestCase): def test_invalid_file_does_not_throw(self): parsed_map = Sourcemap.ParsedSourceMap("") + self.assertFalse(parsed_map.is_valid()) self.assertFalse(parsed_map.content) + def test_valid_json_invalid_map_does_not_throw(self): + parsed_map = Sourcemap.ParsedSourceMap(assets_path + "randomjson.js.map") # exists, but not valid map file + self.assertFalse(parsed_map.is_valid()) + def test_invalid_file_returns_empty_authored_list(self): parsed_map = Sourcemap.ParsedSourceMap("") + self.assertFalse(parsed_map.is_valid()) self.assertEqual(len(parsed_map.get_authored_sources_path()), 0) def test_valid_map_file_parsing(self): parsed_map = Sourcemap.ParsedSourceMap(assets_path + "app.js.map") + self.assertTrue(parsed_map.is_valid()) self.assertTrue(parsed_map.content) def test_valid_map_authored_list(self): parsed_map = Sourcemap.ParsedSourceMap(assets_path + "app.js.map") - + self.assertTrue(parsed_map.is_valid()) self.assertEqual(parsed_map.version, 3) self.assertEqual(len(parsed_map.get_authored_sources_path()), 1) self.assertEqual(parsed_map.get_authored_sources_path(), [assets_path + "app.ts"]) diff --git a/tests/TestRunner.py b/tests/TestRunner.py index dd6cc75..8795536 100644 --- a/tests/TestRunner.py +++ b/tests/TestRunner.py @@ -20,3 +20,5 @@ def registerAndRunTests(className): registerAndRunTests(DocumentMappingTests.PositionTests) registerAndRunTests(DocumentMappingTests.MappingInfoTests) registerAndRunTests(DocumentMappingTests.MappingsManagerTests) + +print("Done tests...") diff --git a/tests/assets/randomjson.js b/tests/assets/randomjson.js new file mode 100644 index 0000000..e275ede --- /dev/null +++ b/tests/assets/randomjson.js @@ -0,0 +1,4 @@ +window.onload = function () { +}; + +//# sourceMappingURL=randomjson.js.map \ No newline at end of file diff --git a/tests/assets/randomjson.js.map b/tests/assets/randomjson.js.map new file mode 100644 index 0000000..f6864dd --- /dev/null +++ b/tests/assets/randomjson.js.map @@ -0,0 +1,3 @@ +{ + "validjson": "invalidmap" +} \ No newline at end of file diff --git a/tests/runtests.sh b/tests/runtests.sh index 4b67dd4..43172a3 100644 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -1,4 +1,7 @@ #!/bin/bash +#set up with something like +#export pythonpath=c:/python34 + dir=`dirname "$0"` $pythonpath/python.exe "$dir/TestRunner.py"