Repository: python-metar/python-metar

Issue:
local variable 'precip_text' referenced before assignment in present_weather output
Automatic report could broke the present weather output.

 This METAR : 
`METAR FSIA 220100Z AUTO 14014KT 120V180 9999 ///////// 27/23 Q1010`

gives an error when the method present_weather is triggered: 
```
UnboundLocalError: local variable 'precip_text' referenced before assignment
```


Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/python-metar/python-metar/pull/68?src=pr&el=h1) Report
> Merging [#68](https://codecov.io/gh/python-metar/python-metar/pull/68?src=pr&el=desc) into [master](https://codecov.io/gh/python-metar/python-metar/commit/f092a1bf3a8b35a0366b6c5f42fe8fea6bdba093?src=pr&el=desc) will **increase** coverage by `2.28%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/python-metar/python-metar/pull/68/graphs/tree.svg?width=650&token=W7CMdTTvRY&height=150&src=pr)](https://codecov.io/gh/python-metar/python-metar/pull/68?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #68      +/-   ##
==========================================
+ Coverage   72.88%   75.17%   +2.28%     
==========================================
  Files           4        4              
  Lines        1018     1019       +1     
==========================================
+ Hits          742      766      +24     
+ Misses        276      253      -23
```


| [Impacted Files](https://codecov.io/gh/python-metar/python-metar/pull/68?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [metar/Metar.py](https://codecov.io/gh/python-metar/python-metar/pull/68/diff?src=pr&el=tree#diff-bWV0YXIvTWV0YXIucHk=) | `69.95% <100%> (+3.65%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/python-metar/python-metar/pull/68?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/python-metar/python-metar/pull/68?src=pr&el=footer). Last update [f092a1b...cdceeb0](https://codecov.io/gh/python-metar/python-metar/pull/68?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

coveralls: ## Pull Request Test Coverage Report for [Build 62](https://coveralls.io/builds/19177547)

* **4** of **4**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**2.3%**) to **75.172%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/19177547/badge)](https://coveralls.io/builds/19177547) |
| :-- | --: |
| Change from base [Build 61](https://coveralls.io/builds/19169388): |  2.3% |
| Covered Lines: | 766 |
| Relevant Lines: | 1019 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/metar/Metar.py b/metar/Metar.py
index 7cbcaac..7d5c0a7 100755
--- a/metar/Metar.py
+++ b/metar/Metar.py
@@ -649,7 +649,7 @@ class Metar(object):
             high = distance(d['high'], unit)
         self.runway.append([d['name'], low, high, unit])
 
-    def _handleWeather( self, d ):
+    def _handleWeather(self, d):
         """
         Parse a present-weather group.
 
@@ -668,7 +668,7 @@ class Metar(object):
         preci = d['prec']
         obsci = d['obsc']
         otheri = d['other']
-        self.weather.append((inteni,desci,preci,obsci,otheri))
+        self.weather.append((inteni, desci, preci, obsci, otheri))
 
     def _handleSky( self, d ):
         """
@@ -1200,7 +1200,7 @@ class Metar(object):
         """
         text_list = []
         for weatheri in weather:
-            (inteni,desci,preci,obsci,otheri) = weatheri
+            (inteni, desci, preci, obsci, otheri) = weatheri
             text_parts = []
             code_parts = []
             if inteni:
@@ -1223,6 +1223,8 @@ class Metar(object):
                     precip_text = WEATHER_PREC[preci[:2]]+", "
                     precip_text += WEATHER_PREC[preci[2:4]]+" and "
                     precip_text += WEATHER_PREC[preci[4:]]
+                else:
+                    precip_text = preci
                 if desci == "TS":
                     text_parts.append("with")
                 text_parts.append(precip_text)


Test patch:
diff --git a/test/test_metar.py b/test/test_metar.py
index 5482a03..05392a6 100644
--- a/test/test_metar.py
+++ b/test/test_metar.py
@@ -30,6 +30,15 @@ class MetarTest(unittest.TestCase):
         )
         self.assertEqual(res, ans)
 
+    def test_issue67_precip_text(self):
+        """Check that precip_text is properly defined in present_weather."""
+        report = Metar.Metar(
+            "METAR FSIA 220100Z AUTO 14014KT 120V180 9999 ///////// "
+            "27/23 Q1010"
+        )
+        res = report.present_weather()
+        self.assertEqual(res, "/////////")
+
     def test_issue40_runwayunits(self):
         """Check reported units on runway visual range."""
         report = Metar.Metar(