def test_removes_given_resources_if_safe(self): temp, temp_path = tempfile.mkstemp() os.close(temp) issue = clean_app.UnusedResourceIssue(temp_path, True) clean_app.remove_unused_resources([issue], os.path.dirname(temp_path), False) with self.assertRaises(IOError): open(temp_path)
def test_remove_value_only_if_the_file_still_exists(self): temp, temp_path = tempfile.mkstemp() os.close(temp) os.remove(temp_path) issue = clean_app.UnusedResourceIssue(temp_path, False) issue.add_element('The resource `R.drawable.drawable_missing` appears to be unused') clean_app.remove_unused_resources([issue], os.path.dirname(temp_path), False)
def test_ignores_layouts(self): temp, temp_path = tempfile.mkstemp() os.write(temp, """ <resources> <string name="app_name">android_app</string> <layout name="missing">missing</layout> <string name="app_name1">android_app1</string> </resources> """.encode('UTF-8')) os.close(temp) issue = clean_app.UnusedResourceIssue(temp_path, False) issue.add_element('The resource R.string.missing appears to be unused') clean_app.remove_unused_resources([issue], os.path.dirname(temp_path), False) root = ET.parse(temp_path).getroot() self.assertEqual(1, len(root.findall('layout')))
def _removes_an_unused_value_from_a_file(self, message, expected_elements_count=2): temp, temp_path = tempfile.mkstemp() os.write(temp, """ <resources> <string name="app_name">android_app</string> <string name="missing">missing</string> <string name="app_name1">android_app1</string> </resources> """.encode('utf-8')) os.close(temp) issue = clean_app.UnusedResourceIssue(temp_path, False) issue.add_element(message) clean_app.remove_unused_resources([issue], os.path.dirname(temp_path), True) root = ET.parse(temp_path).getroot() self.assertEqual(expected_elements_count, len(root.findall('string')))