Repository: XLSForm/pyxform
Pull request #458 (2020-07-17 12:57:57)

Fixed new non-text calculations output a missing-label warning
Closes #
#451 
#### Why is this the best possible solution? Were any other approaches considered?
The simplest one.
#### What are the regression risks?
None.
#### Does this change require updates to documentation? If so, please file an issue [here](https://github.com/XLSForm/xlsform.github.io) and include the link below.
None.
#### Before submitting this PR, please make sure you have:
- [x] included test cases for core behavior and edge cases in `tests_v1`
- [x] run `nosetests` and verified all tests pass
- [x] run `black pyxform` to format code
- [x] verified that any code or assets from external sources are properly credited in comments


Patch:
diff --git a/pyxform/xls2json.py b/pyxform/xls2json.py
index a7b273d..057f841 100644
--- a/pyxform/xls2json.py
+++ b/pyxform/xls2json.py
@@ -883,6 +883,11 @@ def workbook_to_json(
             constants.LABEL not in row
             and row.get(constants.MEDIA) is None
             and question_type not in aliases.label_optional_types
+            and not row.get("bind", {}).get("calculate")
+            and not (
+                row.get("default")
+                and default_is_dynamic(row.get("default"), question_type)
+            )
         ):
             # TODO: Should there be a default label?
             #      Not sure if we should throw warnings for groups...


Test patch:
diff --git a/pyxform/tests_v1/test_typed_calculates.py b/pyxform/tests_v1/test_typed_calculates.py
index a58ecd6..ad1a901 100644
--- a/pyxform/tests_v1/test_typed_calculates.py
+++ b/pyxform/tests_v1/test_typed_calculates.py
@@ -60,6 +60,72 @@ class TypedCalculatesTest(PyxformTestCase):
             xml__excludes=["input"],
         )
 
+    def test_non_calculate_type_with_calculation_no_warns(self):
+        warnings = []
+
+        self.md_to_pyxform_survey(
+            """
+            | survey |           |      |             |      |             |
+            |        | type      | name | label       | hint | calculation |
+            |        | dateTime  | a    |             |      | now()       |
+            |        | integer   | b    |             |      | 1 div 1     |
+            |        | note      | note | Hello World |      |             |
+            """,
+            warnings=warnings,
+        )
+
+        self.assertTrue(len(warnings) == 0)
+
+    def test_non_calculate_type_with_hint_and_no_calculation_warns(self):
+        warnings = []
+
+        self.md_to_pyxform_survey(
+            """
+            | survey |           |      |             |           |             |
+            |        | type      | name | label       | hint      | calculation |
+            |        | dateTime  | a    |             |           | now()       |
+            |        | integer   | b    |             | Some hint |             |
+            |        | note      | note | Hello World |           |             |
+            """,
+            warnings=warnings,
+        )
+
+        self.assertTrue(len(warnings) == 1)
+        self.assertTrue("Question has no label" in warnings[0])
+
+    def test_non_calculate_type_with_calculation_and_dynamic_default_warns(self):
+        warnings = []
+
+        self.md_to_pyxform_survey(
+            """
+            | survey |           |      |             |      |             |         |
+            |        | type      | name | label       | hint | calculation | default |
+            |        | dateTime  | a    |             |      | now()       |         |
+            |        | integer   | b    |             |      | 1 div 1     | $(a)    |
+            |        | note      | note | Hello World |      |             |         |
+            """,
+            warnings=warnings,
+        )
+
+        self.assertTrue(len(warnings) == 1)
+        self.assertTrue("This form definition contains dynamic defaults" in warnings[0])
+
+    def test_non_calculate_type_with_calculation_and_default_no_warns(self):
+        warnings = []
+
+        self.md_to_pyxform_survey(
+            """
+            | survey |           |      |             |      |             |         |
+            |        | type      | name | label       | hint | calculation | default |
+            |        | dateTime  | a    |             |      | now()       |         |
+            |        | integer   | b    |             |      | 1 div 1     | 1       |
+            |        | note      | note | Hello World |      |             |         |
+            """,
+            warnings=warnings,
+        )
+
+        self.assertTrue(len(warnings) == 0)
+
     def test_select_type_with_calculation_and_no_label_has_no_control(self):
         self.assertPyxformXform(
             name="calculate-select",