def test_removes_given_resources_if_safe(self):
        temp, temp_path = tempfile.mkstemp()
        os.close(temp)

        issue = clean_app.Issue(temp_path, True)

        clean_app.remove_unused_resources([issue], os.path.dirname(temp_path), False)
        with self.assertRaises(IOError):
            open(temp_path)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def test_removes_an_extra_translation_value_from_a_file(self, ):
        temp, temp_path = tempfile.mkstemp()
        os.write(temp, """
            <resources>
                <string name="app_name">android_app</string>
                <string name="extra">extra translation</string>
            </resources>
        """.encode('utf-8'))
        os.close(temp)

        issue = clean_app.ExtraTranslationIssue(temp_path, False)
        issue.add_element('The resource string "`extra`" has been marked as `translatable="false"`')
        clean_app.remove_unused_resources([issue], os.path.dirname(temp_path), True)

        root = ET.parse(temp_path).getroot()
        self.assertEqual(1, len(root.findall('string')))
    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>
        """)
        os.close(temp)

        issue = clean_app.Issue(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')))
Ejemplo n.º 5
0
    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')))
    def test_removes_an_unused_value_from_a_file(self):
        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.Issue(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), True)

        root = ET.parse(temp_path).getroot()
        self.assertEqual(2, len(root.findall('string')))
Ejemplo n.º 7
0
    def test_removes_an_unused_value_from_a_file(self):
        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.Issue(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), True)

        root = ET.parse(temp_path).getroot()
        self.assertEqual(2, len(root.findall('string')))