Skip to content

Commit

Permalink
Fix is_valid() and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danmoseley committed Sep 1, 2015
1 parent 763361d commit bc77938
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion projectsystem/Sourcemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
13 changes: 10 additions & 3 deletions tests/SourcemapTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"])
Expand Down
2 changes: 2 additions & 0 deletions tests/TestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ def registerAndRunTests(className):
registerAndRunTests(DocumentMappingTests.PositionTests)
registerAndRunTests(DocumentMappingTests.MappingInfoTests)
registerAndRunTests(DocumentMappingTests.MappingsManagerTests)

print("Done tests...")
4 changes: 4 additions & 0 deletions tests/assets/randomjson.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/assets/randomjson.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/runtests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

#set up with something like
#export pythonpath=c:/python34

dir=`dirname "$0"`
$pythonpath/python.exe "$dir/TestRunner.py"

0 comments on commit bc77938

Please sign in to comment.