@@ -1334,7 +1334,7 @@ def test_check_uploaded_folder(monkeypatch, tmpdir, caplog):
1334
1334
assert "The total size is 15.0 MB" in caplog .text
1335
1335
assert "3 files were uploaded" in caplog .text
1336
1336
assert "files:\n 6.0 MB: c.jpg\n 5.0 MB: b.txt\n 4.0 MB: a.png\n Perhaps" in caplog .text # tests the order
1337
- assert "create a `.lightningignore` file " in caplog .text
1337
+ assert "adding them to `.lightningignore`. " in caplog .text
1338
1338
assert "lightningingore` attribute in a Flow or Work" in caplog .text
1339
1339
1340
1340
@@ -1571,6 +1571,56 @@ def run(self):
1571
1571
flow .run ()
1572
1572
1573
1573
1574
+ def test_default_lightningignore (monkeypatch , caplog , tmpdir ):
1575
+ mock_client = mock .MagicMock ()
1576
+ mock_client .projects_service_list_memberships .return_value = V1ListMembershipsResponse (
1577
+ memberships = [V1Membership (name = "test-project" , project_id = "test-project-id" )]
1578
+ )
1579
+ mock_client .lightningapp_instance_service_list_lightningapp_instances .return_value = (
1580
+ V1ListLightningappInstancesResponse (lightningapps = [])
1581
+ )
1582
+ mock_client .lightningapp_v2_service_create_lightningapp_release .return_value = V1LightningappRelease (
1583
+ cluster_id = "test"
1584
+ )
1585
+ cloud_backend = mock .MagicMock (client = mock_client )
1586
+ monkeypatch .setattr (backends , "CloudBackend" , mock .MagicMock (return_value = cloud_backend ))
1587
+
1588
+ class MyWork (LightningWork ):
1589
+ def run (self ):
1590
+ pass
1591
+
1592
+ app = LightningApp (MyWork ())
1593
+
1594
+ path = Path (tmpdir )
1595
+ cloud_runtime = cloud .CloudRuntime (app = app , entrypoint_file = path / "entrypoint.py" )
1596
+ monkeypatch .setattr (LocalSourceCodeDir , "upload" , mock .MagicMock ())
1597
+
1598
+ # write some files
1599
+ write_file_of_size (path / "a.txt" , 5 * 1000 * 1000 )
1600
+ write_file_of_size (path / "venv" / "foo.txt" , 4 * 1000 * 1000 )
1601
+
1602
+ assert not (path / ".lightningignore" ).exists ()
1603
+
1604
+ with mock .patch (
1605
+ "lightning_app.runners.cloud._parse_lightningignore" , wraps = _parse_lightningignore
1606
+ ) as parse_mock , mock .patch (
1607
+ "lightning_app.source_code.local._copytree" , wraps = _copytree
1608
+ ) as copy_mock , caplog .at_level (
1609
+ logging .WARN
1610
+ ):
1611
+ cloud_runtime .dispatch ()
1612
+
1613
+ parse_mock .assert_called_once_with (())
1614
+ assert copy_mock .mock_calls [0 ].kwargs ["ignore_functions" ][0 ].args [1 ] == set ()
1615
+
1616
+ assert (path / ".lightningignore" ).exists ()
1617
+
1618
+ assert f"Your application folder '{ path .absolute ()} ' is more than 2 MB" in caplog .text
1619
+ assert "The total size is 5.0 MB" in caplog .text
1620
+ assert "2 files were uploaded" # a.txt and .lightningignore
1621
+ assert "files:\n 5.0 MB: a.txt\n Perhaps" in caplog .text # only this file appears
1622
+
1623
+
1574
1624
@pytest .mark .parametrize (
1575
1625
"lightning_app_instance, lightning_cloud_url, expected_url" ,
1576
1626
[
0 commit comments