Ejemplo n.º 1
0
 def test_can_write_package_with_class(self):
     EXPECTED = """var com=(function(window,undefined){var Test=function(){};var example=(function(window,undefined){return {};}(window));return {"Test":Test,"example":example};}(window));"""
     com = Package("com")
     com.packages["example"] = Package("example")
     TestClass = mock.Mock(spec=Class)
     TestClass.to_js = mock.Mock(return_value="var Test=function(){};")
     TestClass.visibility = Class.PUBLIC
     com.classes["Test"] = TestClass
     def print_diff():
         print [x for x in difflib.ndiff(EXPECTED,com.to_js())]
     self.assertEqual(EXPECTED,com.to_js(),print_diff());
     assert_that(com.to_js(), equal_to(EXPECTED))
     
Ejemplo n.º 2
0
class TestPackage(TestCase):
    def setUp(self):
        self.pack = Package("com")
        
    def test_initial_state(self):
        self.assertEqual(0,len(self.pack.packages))
        self.assertEqual("com",self.pack.name)
        
    def test_cannot_write_to_name(self):
        try:
            self.pack.name = "hello"
            self.fail("Should not be able to write to name field.")
        except AttributeError:
            pass
        
    def test_can_add_subpackages(self):
        pack2 = Package("example")
        self.pack.packages["example"] = pack2
        self.assertEqual(pack2.name,self.pack.packages.keys()[0])
        
    def test_can_write_simple_package_properly(self):
        EXPECTED = "var com=(function(window,undefined){return {};}(window));"
        self.assertEqual(EXPECTED,self.pack.to_js())
        
    def test_can_write_hierarchical_package_properly(self):
        EXPECTED = "var com=(function(window,undefined){var example=(function(window,undefined){var deeper=(function(window,undefined){return {};}(window));return {\"deeper\":deeper};}(window));var example2=(function(window,undefined){return {};}(window));return {\"example\":example,\"example2\":example2};}(window));"
        example = Package("example")
        example.packages["deeper"] = Package("deeper")
        self.pack.packages["example"] = example
        self.pack.packages["example2"] = Package("example2")
        assert_that(self.pack.to_js(), equal_to(EXPECTED))
        
    def test_can_write_package_with_class(self):
        EXPECTED = """var com=(function(window,undefined){var Test=function(){};var example=(function(window,undefined){return {};}(window));return {"Test":Test,"example":example};}(window));"""
        com = Package("com")
        com.packages["example"] = Package("example")
        TestClass = mock.Mock(spec=Class)
        TestClass.to_js = mock.Mock(return_value="var Test=function(){};")
        TestClass.visibility = Class.PUBLIC
        com.classes["Test"] = TestClass
        def print_diff():
            print [x for x in difflib.ndiff(EXPECTED,com.to_js())]
        self.assertEqual(EXPECTED,com.to_js(),print_diff());
        assert_that(com.to_js(), equal_to(EXPECTED))