From: Nick Morrott <knowledgejunkie@gmail.com>
Date: Sun, 24 May 2020 10:21:35 -0700
Subject: use the packaged version of uflash.py

Forwarded: not-needed
Last-Update: 2018-12-21

During repacking of the upstream source we remove the convenience copy of
uflash.py, which is provided on Debian in the python3-uflash package
Last-Update: 2018-12-21
---
 mu/modes/microbit.py         |  3 ++-
 tests/modes/test_microbit.py | 34 +++++++++++++++++-----------------
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/mu/modes/microbit.py b/mu/modes/microbit.py
index 7aa8ff7..80a206b 100644
--- a/mu/modes/microbit.py
+++ b/mu/modes/microbit.py
@@ -24,7 +24,8 @@ import logging
 import semver
 from tokenize import TokenError
 from mu.logic import HOME_DIRECTORY
-from mu.contrib import uflash, microfs
+import uflash
+from mu.contrib import microfs
 from mu.modes.api import MICROBIT_APIS, SHARED_APIS
 from mu.modes.base import MicroPythonMode
 from mu.interface.panes import CHARTS
diff --git a/tests/modes/test_microbit.py b/tests/modes/test_microbit.py
index b966f34..0270983 100644
--- a/tests/modes/test_microbit.py
+++ b/tests/modes/test_microbit.py
@@ -8,7 +8,7 @@ import pytest
 from mu.logic import HOME_DIRECTORY
 from mu.modes.microbit import MicrobitMode, FileManager, DeviceFlasher
 from mu.modes.api import MICROBIT_APIS, SHARED_APIS
-from mu.contrib import uflash
+import uflash
 from unittest import mock
 from tokenize import TokenError
 
@@ -671,7 +671,7 @@ def test_force_flash_no_serial_connection():
     """
     mock_flasher = mock.MagicMock()
     mock_flasher_class = mock.MagicMock(return_value=mock_flasher)
-    with mock.patch('mu.contrib.uflash.find_microbit',
+    with mock.patch('uflash.find_microbit',
                     return_value='bar'),\
             mock.patch('mu.contrib.microfs.get_serial'),\
             mock.patch('mu.contrib.microfs.version',
@@ -710,7 +710,7 @@ def test_force_flash_empty_script():
     }
     mock_flasher = mock.MagicMock()
     mock_flasher_class = mock.MagicMock(return_value=mock_flasher)
-    with mock.patch('mu.contrib.uflash.find_microbit',
+    with mock.patch('uflash.find_microbit',
                     return_value='bar'),\
             mock.patch('mu.contrib.microfs.get_serial'),\
             mock.patch('mu.contrib.microfs.version',
@@ -749,7 +749,7 @@ def test_force_flash_user_specified_device_path():
     }
     mock_flasher = mock.MagicMock()
     mock_flasher_class = mock.MagicMock(return_value=mock_flasher)
-    with mock.patch('mu.contrib.uflash.find_microbit',
+    with mock.patch('uflash.find_microbit',
                     return_value=None),\
             mock.patch('mu.contrib.microfs.get_serial'),\
             mock.patch('mu.contrib.microfs.version',
@@ -781,12 +781,12 @@ def test_flash_path_specified_does_not_exist():
     user has previously specified a path to the device, then the hex is saved
     in the specified location.
     """
-    with mock.patch('mu.contrib.uflash.hexlify', return_value=''), \
-            mock.patch('mu.contrib.uflash.embed_hex', return_value='foo'), \
-            mock.patch('mu.contrib.uflash.find_microbit', return_value=None),\
+    with mock.patch('uflash.hexlify', return_value=''), \
+            mock.patch('uflash.embed_hex', return_value='foo'), \
+            mock.patch('uflash.find_microbit', return_value=None),\
             mock.patch('mu.logic.os.path.exists', return_value=False),\
             mock.patch('mu.logic.os.makedirs', return_value=None), \
-            mock.patch('mu.contrib.uflash.save_hex', return_value=None) as s:
+            mock.patch('uflash.save_hex', return_value=None) as s:
         view = mock.MagicMock()
         view.current_tab.text = mock.MagicMock(return_value='')
         view.show_message = mock.MagicMock()
@@ -811,10 +811,10 @@ def test_flash_without_device():
     If no device is found and the user doesn't provide a path then ensure a
     helpful status message is enacted.
     """
-    with mock.patch('mu.contrib.uflash.hexlify', return_value=''), \
-            mock.patch('mu.contrib.uflash.embed_hex', return_value='foo'), \
-            mock.patch('mu.contrib.uflash.find_microbit', return_value=None),\
-            mock.patch('mu.contrib.uflash.save_hex', return_value=None) as s:
+    with mock.patch('uflash.hexlify', return_value=''), \
+            mock.patch('uflash.embed_hex', return_value='foo'), \
+            mock.patch('uflash.find_microbit', return_value=None),\
+            mock.patch('uflash.save_hex', return_value=None) as s:
         view = mock.MagicMock()
         view.get_microbit_path = mock.MagicMock(return_value=None)
         view.current_tab.text = mock.MagicMock(return_value='')
@@ -1317,7 +1317,7 @@ def test_open_hex():
     mock_open = mock.mock_open()
     hex_extracted = 'RECOVERED'
     with mock.patch('builtins.open', mock_open), \
-            mock.patch('mu.contrib.uflash.extract_script',
+            mock.patch('uflash.extract_script',
                        return_value=hex_extracted) as extract_script:
         text = mm.open_file('path_to_file.hex')
     assert text == hex_extracted
@@ -1326,7 +1326,7 @@ def test_open_hex():
 
     mock_open.reset_mock()
     with mock.patch('builtins.open', mock_open), \
-            mock.patch('mu.contrib.uflash.extract_script',
+            mock.patch('uflash.extract_script',
                        return_value=hex_extracted) as extract_script:
         text = mm.open_file('path_to_file.HEX')
     assert text == hex_extracted
@@ -1343,7 +1343,7 @@ def test_open_ignore_non_hex():
     mm = MicrobitMode(editor, view)
     mock_open = mock.mock_open()
     with mock.patch('builtins.open', mock_open), \
-            mock.patch('mu.contrib.uflash.extract_script',
+            mock.patch('uflash.extract_script',
                        return_value='Should not be called') as extract_script:
         text = mm.open_file('path_to_file.py')
     assert text is None
@@ -1352,7 +1352,7 @@ def test_open_ignore_non_hex():
 
     mock_open.reset_mock()
     with mock.patch('builtins.open', mock_open), \
-            mock.patch('mu.contrib.uflash.extract_script',
+            mock.patch('uflash.extract_script',
                        return_value='Should not be called') as extract_script:
         text = mm.open_file('file_no_extension')
     assert text is None
@@ -1371,7 +1371,7 @@ def test_open_hex_with_exception():
     mock_open = mock.mock_open()
     mock_extract = mock.MagicMock(side_effect=Exception(':('))
     with mock.patch('builtins.open', mock_open), \
-            mock.patch('mu.contrib.uflash.extract_script', mock_extract):
+            mock.patch('uflash.extract_script', mock_extract):
         text = mm.open_file('path_to_file.hex')
     assert text is None
     assert mock_extract.call_count == 1
