示例#1
0
    def test_connection_with_predicate(self):
        program = "[viewOne]-50-[viewTwo]"
        result = Parser.parse(program)

        connection = result.views[0].following_connection
        self.assertIsInstance(connection.predicates, list)
        self.assertTrue(len(connection.predicates) == 1)
        self.assertIsInstance(connection.predicates[0], Predicate)
示例#2
0
    def test_view_width_constraint(self):
        program = "[testView(>=50)]"
        result = Parser.parse(program)

        test_view = result.get_view("testView")
        self.assertIsInstance(test_view, View)

        self.assertIsInstance(test_view.constraints, list)
示例#3
0
    def test_simple_predicate(self):
        program = "[testView]-50-[anotherView]"
        result = Parser.parse(program)
        view = result.get_view("testView")
        connection = view.following_connection

        predicate = connection.predicates[0]

        self.assertIsInstance(predicate, Predicate)
示例#4
0
    def test_get_view(self):
        program = "[testView][anotherView][yetAnotherView]"

        result = Parser.parse(program)

        expected_view_names = ["testView", "anotherView", "yetAnotherView"]

        for view_name in expected_view_names:
            self.assertIsInstance(result.get_view(view_name), View)
            self.assertEqual(result.get_view(view_name).name, view_name)
示例#5
0
    def test_standard_space(self):
        program = "[viewOne]-[viewTwo]"
        result = Parser.parse(program)

        self.assertEqual(len(result.views), 2)
        self.assertEqual(len(result.children), 3)

        expected = [View, Connection, View]

        # Expect order of children
        for idx, item in enumerate(expected):
            self.assertIsInstance(result.children[idx], expected[idx])
示例#6
0
    def test_basic_connection(self):
        program = "[viewOne]-[viewTwo]"
        result = Parser.parse(program)

        view_one = result.views[0]
        view_two = result.views[1]

        connection = result.views[0].following_connection

        # Make sure its the same connection instance attached to both
        # view instances
        self.assertEqual(connection, result.views[1].preceding_connection)

        # Assert that theres no connections where there shouldn't be
        self.assertIsNone(view_one.preceding_connection)
        self.assertIsNone(view_two.following_connection)

        self.assertIsInstance(view_one.following_connection, Connection)
        self.assertIsInstance(view_two.preceding_connection, Connection)

        self.assertEquals(connection.following_view, view_two)
        self.assertEquals(connection.preceding_view, view_one)
示例#7
0
    def test_parse_returns_view(self):
        program = "[testView]"
        result = Parser.parse(program)

        self.assertIsInstance(result, View)
示例#8
0
    def test_has_superview_is_false(self):
        program = "[purpleBox]"
        result = Parser.parse(program)

        self.assertFalse(result.has_superview())
示例#9
0
    def test_has_superview_is_true(self):
        program = "|-50-[purpleBox]-50-|"
        result = Parser.parse(program)

        self.assertTrue(result.has_superview())
示例#10
0
 def test_flush_views(self):
     program = "[viewOne][viewTwo]"
     result = Parser.parse(program)
     self.assertEqual(len(result.views), 2)
     self.assertEqual(len(result.children), 2)
示例#11
0
 def test_program_collects_child_views(self):
     program = "[testView]"
     result = Parser.parse(program)
     self.assertEqual(len(result.views), 1)
     self.assertEqual(len(result.children), 1)
     self.assertEqual(result.views[0].name, "testView")
示例#12
0
文件: init.py 项目: chazu/python-vfl
from vfl.parser import Parser

# result = Parser.parse("H:[viewName(==50@10)]")
# result = Parser.parse("[viewName(>=50,<=100)]-50-[anotherView]")
# result = Parser.parse("H:[viewName(30,==anotherView)]")
result = Parser.parse("|-50-[purpleBox]-50-|")

print(result)