@@ -35,6 +35,7 @@ def wait_for_text_to_equal(self, selector, assertion_text):
35
35
except Exception as e :
36
36
pass
37
37
time .sleep (0.25 )
38
+
38
39
raise e
39
40
40
41
def request_queue_assertions (
@@ -1651,3 +1652,118 @@ def display_tab2_output(value):
1651
1652
self .assertEqual (call_counts ['tab2' ].value , 1 )
1652
1653
1653
1654
assert_clean_console (self )
1655
+
1656
+ def test_initialization_with_overlapping_outputs (self ):
1657
+ app = dash .Dash ()
1658
+ app .layout = html .Div ([
1659
+
1660
+ html .Div (id = 'input-1' , children = 'input-1' ),
1661
+ html .Div (id = 'input-2' , children = 'input-2' ),
1662
+ html .Div (id = 'input-3' , children = 'input-3' ),
1663
+ html .Div (id = 'input-4' , children = 'input-4' ),
1664
+ html .Div (id = 'input-5' , children = 'input-5' ),
1665
+
1666
+ html .Div (id = 'output-1' ),
1667
+ html .Div (id = 'output-2' ),
1668
+ html .Div (id = 'output-3' ),
1669
+ html .Div (id = 'output-4' ),
1670
+
1671
+ ])
1672
+ call_counts = {
1673
+ 'output-1' : Value ('i' , 0 ),
1674
+ 'output-2' : Value ('i' , 0 ),
1675
+ 'output-3' : Value ('i' , 0 ),
1676
+ 'output-4' : Value ('i' , 0 ),
1677
+ }
1678
+
1679
+ def generate_callback (outputid ):
1680
+ def callback (* args ):
1681
+ call_counts [outputid ].value += 1
1682
+ return str (args )
1683
+ return callback
1684
+
1685
+ for i in range (1 , 5 ):
1686
+ outputid = 'output-{}' .format (i )
1687
+ app .callback (
1688
+ Output (outputid , 'children' ),
1689
+ [Input ('input-{}' .format (i ), 'children' ),
1690
+ Input ('input-{}' .format (i + 1 ), 'children' )]
1691
+ )(generate_callback (outputid ))
1692
+
1693
+ self .startServer (app )
1694
+
1695
+ self .wait_for_element_by_css_selector ('#output-1' )
1696
+ time .sleep (5 )
1697
+
1698
+ for i in range (1 , 5 ):
1699
+ outputid = 'output-{}' .format (i )
1700
+ self .assertEqual (call_counts [outputid ].value , 1 )
1701
+ self .wait_for_text_to_equal (
1702
+ '#{}' .format (outputid ),
1703
+ "(u'input-{}', u'input-{}')" .format (i , i + 1 )
1704
+ )
1705
+
1706
+ def test_generate_overlapping_outputs (self ):
1707
+ app = dash .Dash ()
1708
+ app .config ['suppress_callback_exceptions' ] = True
1709
+ block = html .Div ([
1710
+
1711
+ html .Div (id = 'input-1' , children = 'input-1' ),
1712
+ html .Div (id = 'input-2' , children = 'input-2' ),
1713
+ html .Div (id = 'input-3' , children = 'input-3' ),
1714
+ html .Div (id = 'input-4' , children = 'input-4' ),
1715
+ html .Div (id = 'input-5' , children = 'input-5' ),
1716
+
1717
+ html .Div (id = 'output-1' ),
1718
+ html .Div (id = 'output-2' ),
1719
+ html .Div (id = 'output-3' ),
1720
+ html .Div (id = 'output-4' ),
1721
+
1722
+ ])
1723
+ app .layout = html .Div ([
1724
+ html .Div (id = 'input' ),
1725
+ html .Div (id = 'container' )
1726
+ ])
1727
+
1728
+ call_counts = {
1729
+ 'container' : Value ('i' , 0 ),
1730
+ 'output-1' : Value ('i' , 0 ),
1731
+ 'output-2' : Value ('i' , 0 ),
1732
+ 'output-3' : Value ('i' , 0 ),
1733
+ 'output-4' : Value ('i' , 0 ),
1734
+ }
1735
+
1736
+ @app .callback (Output ('container' , 'children' ),
1737
+ [Input ('input' , 'children' )])
1738
+ def display_output (* args ):
1739
+ call_counts ['container' ].value += 1
1740
+ return block
1741
+
1742
+ def generate_callback (outputid ):
1743
+ def callback (* args ):
1744
+ call_counts [outputid ].value += 1
1745
+ return str (args )
1746
+ return callback
1747
+
1748
+ for i in range (1 , 5 ):
1749
+ outputid = 'output-{}' .format (i )
1750
+ app .callback (
1751
+ Output (outputid , 'children' ),
1752
+ [Input ('input-{}' .format (i ), 'children' ),
1753
+ Input ('input-{}' .format (i + 1 ), 'children' )]
1754
+ )(generate_callback (outputid ))
1755
+
1756
+ self .startServer (app )
1757
+
1758
+ wait_for (lambda : call_counts ['container' ].value == 1 )
1759
+ self .wait_for_element_by_css_selector ('#output-1' )
1760
+ time .sleep (5 )
1761
+
1762
+ for i in range (1 , 5 ):
1763
+ outputid = 'output-{}' .format (i )
1764
+ self .assertEqual (call_counts [outputid ].value , 1 )
1765
+ self .wait_for_text_to_equal (
1766
+ '#{}' .format (outputid ),
1767
+ "(u'input-{}', u'input-{}')" .format (i , i + 1 )
1768
+ )
1769
+ self .assertEqual (call_counts ['container' ].value , 1 )
0 commit comments