コード例 #1
0
 def test_way02(self):
     api = overpy.Overpass()
     # DOM
     result = api.parse_xml(read_file("xml/way-02.xml"),
                            parser=overpy.XML_PARSER_DOM)
     self._test_way02(result)
     # SAX
     result = api.parse_xml(read_file("xml/way-02.xml"),
                            parser=overpy.XML_PARSER_SAX)
     self._test_way02(result)
コード例 #2
0
 def test_relation04(self):
     api = overpy.Overpass()
     # DOM
     result = api.parse_xml(read_file("xml/relation-04.xml"),
                            parser=overpy.XML_PARSER_DOM)
     self._test_relation04(result)
     # SAX
     result = api.parse_xml(read_file("xml/relation-04.xml"),
                            parser=overpy.XML_PARSER_SAX)
     self._test_relation04(result)
コード例 #3
0
 def test_node01(self):
     api = overpy.Overpass()
     # DOM
     result = api.parse_xml(read_file("xml/area-01.xml"),
                            parser=overpy.XML_PARSER_DOM)
     self._test_area01(result)
     # SAX
     result = api.parse_xml(read_file("xml/area-01.xml"),
                            parser=overpy.XML_PARSER_SAX)
     self._test_area01(result)
コード例 #4
0
    def test_way04(self):
        api = overpy.Overpass()
        # DOM
        with pytest.raises(ValueError):
            api.parse_xml(read_file("xml/way-04.xml"),
                          parser=overpy.XML_PARSER_DOM)

        # SAX
        with pytest.raises(ValueError):
            api.parse_xml(read_file("xml/way-04.xml"),
                          parser=overpy.XML_PARSER_SAX)
コード例 #5
0
    def test_path_escape(self):
        c = cache.Cache("__test_path_escape__")

        # create file
        tests.write_file(tests.data_path("tmp", "file.txt", exists=False),
                         "Hello, world!")
        # sanity check
        self.assertEqual(tests.read_file(tests.data_path("tmp", "file.txt")),
                         "Hello, world!")

        # insert file into cache
        key = 'this key/path needs: escaping!.?'
        c[key] = tests.data_path("tmp", "file.txt")

        # check file contents
        self.assertEqual(tests.read_file(c[key]), "Hello, world!")
        c.empty()
コード例 #6
0
    def test_expand_01(self):
        api = overpy.Overpass()
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        assert len(result1.nodes) == 2
        assert len(result1.ways) == 1

        result2 = api.parse_json(read_file("json/result-expand-02.json"))

        assert len(result2.nodes) == 2
        assert len(result2.ways) == 1

        result1.expand(result2)

        # Don't overwrite existing elements
        assert len(result1.nodes) == 3
        assert len(result1.ways) == 2
コード例 #7
0
    def test_expand_01(self):
        api = overpy.Overpass()
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        assert len(result1.nodes) == 2
        assert len(result1.ways) == 1

        result2 = api.parse_json(read_file("json/result-expand-02.json"))

        assert len(result2.nodes) == 2
        assert len(result2.ways) == 1

        result1.expand(result2)

        # Don't overwrite existing elements
        assert len(result1.nodes) == 3
        assert len(result1.ways) == 2
コード例 #8
0
    def test_xml_element(self):
        import xml.etree.ElementTree as ET
        data = read_file("xml/node-01.xml")
        root = ET.fromstring(data)
        result = overpy.Result.from_xml(root)

        assert isinstance(result, overpy.Result)
        self._test_node01(result)
コード例 #9
0
    def test_attribute_invalid_date(self):
        api = overpy.Overpass()
        result = api.parse_json(read_file("json/way-meta_invalid-timestamp.json"))

        for o in result.ways + result.nodes:
            assert(type(o.attributes['uid']) == int)
            assert(type(o.attributes['changeset']) == int)
            assert(type(o.attributes['version']) == int)
            assert('timestamp' in o.attributes)
コード例 #10
0
    def test_execute_fixer(self):
        tool = Flake8(self.problems, {'fixer': True}, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        eq_(0, len(self.problems.all()), 'No errors should be recorded')
コード例 #11
0
 def test_expand_error(self):
     api = overpy.Overpass()
     result = api.parse_json(read_file("json/result-expand-01.json"))
     with pytest.raises(ValueError):
         result.expand(123)
     with pytest.raises(ValueError):
         result.expand(1.23)
     with pytest.raises(ValueError):
         result.expand("abc")
コード例 #12
0
ファイル: test_phpcs.py プロジェクト: esoergel/lint-review
    def test_execute_fixer(self):
        tool = Phpcs(self.problems, {'fixer': True})

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        eq_(0, len(self.problems.all()), 'No errors should be recorded')
コード例 #13
0
 def test_expand_error(self):
     api = overpy.Overpass()
     result = api.parse_json(read_file("json/result-expand-01.json"))
     with pytest.raises(ValueError):
         result.expand(123)
     with pytest.raises(ValueError):
         result.expand(1.23)
     with pytest.raises(ValueError):
         result.expand("abc")
コード例 #14
0
ファイル: test_phpcs.py プロジェクト: esoergel/lint-review
    def test_execute_fixer__no_problems_remain(self):
        tool = Phpcs(self.problems, {'fixer': True})

        # The fixture file can have all problems fixed by phpcs
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        eq_(0, len(self.problems.all()), 'All errors should be autofixed')
コード例 #15
0
ファイル: test_pytype.py プロジェクト: markstory/lint-review
    def test_run_fixer(self):
        tool = Pytype(self.problems, {'fixer': True}, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        self.assertEqual(0, len(self.problems.all()),
                         'No errors should be recorded')
コード例 #16
0
ファイル: test_ktlint.py プロジェクト: markstory/lint-review
    def test_execute_fixer(self):
        tool = Ktlint(self.problems, {'fixer': True}, root_dir)
        target = root_dir + '/' + self.fixtures[1]
        original = read_file(target)
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(target, original)
        assert original != updated, 'File content should change.'
        self.assertEqual(0, len(self.problems.all()),
                         'No errors should be recorded')
コード例 #17
0
    def test_execute_fixer__no_problems_remain(self):
        tool = Phpcs(self.problems, {'fixer': True})

        # The fixture file can have all problems fixed by phpcs
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        eq_(0, len(self.problems.all()), 'All errors should be autofixed')
コード例 #18
0
    def test_missing_unresolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_node(123, resolve_missing=True)
        stop_server_thread(server)
コード例 #19
0
ファイル: test_ktlint.py プロジェクト: jpos15/lint-review
    def test_execute_fixer(self):
        tool = Ktlint(self.problems, {'fixer': True}, root_dir)
        target = root_dir + '/' + self.fixtures[1]
        original = read_file(target)
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(target, original)
        assert original != updated, 'File content should change.'
        self.assertEqual(0, len(self.problems.all()),
                         'No errors should be recorded')
コード例 #20
0
ファイル: test_pep8.py プロジェクト: victorvianna/lint-review
    def test_execute_fixer__python3(self):
        options = {'fixer': True, 'python': 3}
        tool = Pep8(self.problems, options, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        eq_(0, len(self.problems.all()), 'No errors should be recorded')
コード例 #21
0
    def test_missing_unresolvable(self):
        url, t = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_node(123, resolve_missing=True)
        t.join()
コード例 #22
0
    def test_execute_fixer(self):
        tool = Remarklint(self.problems, {'fixer': True}, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        self.assertEqual(1, len(self.problems.all()),
                         'Fewer errors should be recorded')
コード例 #23
0
    def test_set_and_get(self):
        c = cache.Cache("__test_set_and_get__")

        # create file
        tests.write_file(tests.data_path("tmp", "file.txt", exists=False),
                         "Hello, world!")
        # sanity check
        self.assertEqual(tests.read_file(tests.data_path("tmp", "file.txt")),
                         "Hello, world!")

        # insert file into cache
        c['foobar'] = tests.data_path("tmp", "file.txt")

        # file must be in cache
        self.assertTrue(fs.isfile(fs.path(c.path, "foobar")))
        # file must have been moved
        self.assertFalse(fs.isfile(tests.data_path("file.txt", exists=False)))
        # check file contents
        self.assertTrue(tests.read_file(c['foobar']), "Hello, world!")
        c.empty()
コード例 #24
0
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Rubocop(self.problems, {'fixer': True}, root_dir)

        # The fixture file can have all problems fixed by rubocop
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        eq_(1, len(self.problems.all()), 'Most errors should be fixed')
        assert_in('too long', self.problems.all()[0].body)
コード例 #25
0
ファイル: test_pep8.py プロジェクト: jpos15/lint-review
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Pep8(self.problems, {'fixer': True}, root_dir)

        # The fixture file can have all problems fixed by autopep8
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        self.assertGreaterEqual(len(self.problems.all()), 0,
                                'Most errors should be fixed')
コード例 #26
0
    def test_execute_fixer(self):
        tool = Remarklint(self.problems, {'fixer': True}, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        self.assertEqual(1, len(self.problems.all()),
                         'Fewer errors should be recorded')
コード例 #27
0
    def test_execute_fixer(self):
        tool = Eslint(self.problems, {
            'config': 'tests/fixtures/eslint/recommended_config.json',
            'fixer': True,
        }, root_dir)
        original = read_file(FILE_WITH_FIXER_ERRORS)
        tool.execute_fixer([FILE_WITH_FIXER_ERRORS])

        updated = read_and_restore_file(FILE_WITH_FIXER_ERRORS, original)
        assert original != updated, 'File content should change.'
        eq_(0, len(self.problems.all()), 'No errors should be recorded')
コード例 #28
0
ファイル: test_pep8.py プロジェクト: markstory/lint-review
    def test_execute_fixer__python3(self):
        options = {'fixer': True, 'python': 3}
        tool = Pep8(self.problems, options, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        self.assertEqual(0, len(self.problems.all()),
                         'No errors should be recorded')
コード例 #29
0
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Puppet(self.problems, {'fixer': True}, root_dir)

        # The fixture file should have fixable problems fixed
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        eq_(1, len(self.problems.all()), 'Most errors should be fixed')
        assert_in('autoload module layout', self.problems.all()[0].body)
コード例 #30
0
ファイル: test_pep8.py プロジェクト: markstory/lint-review
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Pep8(self.problems, {'fixer': True}, root_dir)

        # The fixture file can have all problems fixed by autopep8
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        self.assertGreaterEqual(len(self.problems.all()), 0,
                                'Most errors should be fixed')
コード例 #31
0
    def test_execute_fixer(self):
        fixture = self.fixtures[1]
        tool = Stylelint(self.problems, {
            'config': 'tests/fixtures/stylelint/stylelintrc.json',
            'fixer': True,
        }, root_dir)
        original = read_file(fixture)
        tool.execute_fixer([fixture])

        updated = read_and_restore_file(fixture, original)
        assert original != updated, 'File content should change.'
コード例 #32
0
    def test_execute_fixer(self):
        fixture = self.fixtures[1]
        tool = Stylelint(self.problems, {
            'config': 'tests/fixtures/stylelint/stylelintrc.json',
            'fixer': True,
        }, root_dir)
        original = read_file(fixture)
        tool.execute_fixer([fixture])

        updated = read_and_restore_file(fixture, original)
        assert original != updated, 'File content should change.'
コード例 #33
0
ファイル: test_puppet.py プロジェクト: markstory/lint-review
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Puppet(self.problems, {'fixer': True}, root_dir)

        # The fixture file should have fixable problems fixed
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        self.assertEqual(1, len(self.problems.all()),
                         'Most errors should be fixed')
        self.assertIn('autoload module layout', self.problems.all()[0].body)
コード例 #34
0
ファイル: test_eslint.py プロジェクト: markstory/lint-review
    def test_execute_fixer(self):
        tool = Eslint(self.problems, {
            'config': 'tests/fixtures/eslint/recommended_config.json',
            'fixer': True,
        }, root_dir)
        original = read_file(FILE_WITH_FIXER_ERRORS)
        tool.execute_fixer([FILE_WITH_FIXER_ERRORS])

        updated = read_and_restore_file(FILE_WITH_FIXER_ERRORS, original)
        assert original != updated, 'File content should change.'
        self.assertEqual(0, len(self.problems.all()),
                         'No errors should be recorded')
コード例 #35
0
ファイル: test_rubocop.py プロジェクト: markstory/lint-review
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Rubocop(self.problems, {'fixer': True}, root_dir)

        # The fixture file can have all problems fixed by rubocop
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        self.assertEqual(1, len(self.problems.all()),
                         'Most errors should be fixed')
        self.assertIn('too long', self.problems.all()[0].body)
コード例 #36
0
    def _clone_define(self, filebase):
        """Take the valid output xml and attempt to define it on the
           connection to ensure we don't get any errors"""
        outfile = os.path.join(clonexml_dir, filebase + "-out.xml")
        outxml = tests.read_file(outfile)

        vm = None
        try:
            vm = conn.defineXML(outxml)
        finally:
            if vm:
                vm.undefine()
コード例 #37
0
    def _clone_define(self, filebase):
        """Take the valid output xml and attempt to define it on the
           connection to ensure we don't get any errors"""
        outfile = os.path.join(clonexml_dir, filebase + "-out.xml")
        outxml = tests.read_file(outfile)

        vm = None
        try:
            vm = conn.defineXML(outxml)
        finally:
            if vm:
                vm.undefine()
コード例 #38
0
ファイル: test_pep8.py プロジェクト: victorvianna/lint-review
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Pep8(self.problems, {'fixer': True}, root_dir)

        # The fixture file can have all problems fixed by autopep8
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        assert len(self.problems.all()) > 0, 'Most errors should be fixed'
        text = [c.body for c in self.problems.all()]
        assert_in("'<>' is deprecated", ' '.join(text))
コード例 #39
0
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Flake8(self.problems, {'fixer': True}, root_dir)

        # The fixture file can have all problems fixed by autopep8
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        assert 1 < len(self.problems.all()), 'Most errors should be fixed'

        text = [c.body for c in self.problems.all()]
        self.assertIn("imported but unused", ' '.join(text))
コード例 #40
0
    def test_execute_fixer__no_problems_remain(self):
        tool = Eslint(self.problems, {
            'config': 'tests/fixtures/eslint/recommended_config.json',
            'fixer': True
        }, root_dir)

        # The fixture file can have all problems fixed by eslint
        original = read_file(FILE_WITH_FIXER_ERRORS)
        tool.execute_fixer([FILE_WITH_FIXER_ERRORS])
        tool.process_files([FILE_WITH_FIXER_ERRORS])

        read_and_restore_file(FILE_WITH_FIXER_ERRORS, original)
        eq_(0, len(self.problems.all()), 'All errors should be autofixed')
コード例 #41
0
ファイル: test_pep8.py プロジェクト: victorvianna/lint-review
    def test_execute_fixer__options(self):
        tool = Pep8(self.problems, {
            'fixer': True,
            'max-line-length': 120,
            'exclude': 'W201'
        }, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        eq_(0, len(self.problems.all()), 'No errors should be recorded')
コード例 #42
0
    def test_way02(self):
        """
        Try to pickle and unpickle the result object
        """
        import pickle

        api = overpy.Overpass()
        result = api.parse_json(read_file("json/way-02.json"))
        self._test_way02(result)
        # do pickle and unpickle
        result_string = pickle.dumps(result)
        new_result = pickle.loads(result_string)
        # test new result
        self._test_way02(new_result)
コード例 #43
0
    def test_execute_fixer__fewer_problems_remain__python3(self):
        options = {'fixer': True, 'python': 3}
        tool = Flake8(self.problems, options, root_dir)

        # The fixture file can have all problems fixed by autopep8
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        assert 1 < len(self.problems.all()), 'Most errors should be fixed'

        text = [c.body for c in self.problems.all()]
        assert_in("'<>' is deprecated", ' '.join(text))
コード例 #44
0
    def test_process_files__missing_plugin(self):
        tool = Remarklint(self.problems, {'fixer': True}, root_dir)

        config = 'tests/fixtures/remarklint/.remarkrc'
        original = read_file(config)
        with open(config, 'w') as f:
            f.write('{"plugins": ["unknown-preset"]}')
        tool.process_files([self.fixtures[1]])

        with open(config, 'w') as f:
            f.write(original)
        problems = self.problems.all()
        self.assertEqual(1, len(problems), 'Should have an error')
        self.assertIn('unknown-preset', problems[0].body)
コード例 #45
0
    def test_overpass_syntax_error_encoding_error(self):
        with pytest.raises(UnicodeDecodeError):
            # File should be encoded with iso8859-15 and will raise an exception
            tmp = read_file("response/bad-request-encoding.html", "rb")
            tmp.decode("utf-8")

        url, server = new_server_thread(HandleOverpassBadRequestEncoding)

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassBadRequest):
            # Missing ; after way(1)
            api.query(("way(1)" "out body;"))
        stop_server_thread(server)
コード例 #46
0
ファイル: test_eslint.py プロジェクト: markstory/lint-review
    def test_execute_fixer__no_problems_remain(self):
        tool = Eslint(self.problems, {
            'config': 'tests/fixtures/eslint/recommended_config.json',
            'fixer': True
        }, root_dir)

        # The fixture file can have all problems fixed by eslint
        original = read_file(FILE_WITH_FIXER_ERRORS)
        tool.execute_fixer([FILE_WITH_FIXER_ERRORS])
        tool.process_files([FILE_WITH_FIXER_ERRORS])

        read_and_restore_file(FILE_WITH_FIXER_ERRORS, original)
        self.assertEqual(0, len(self.problems.all()),
                         'All errors should be autofixed')
コード例 #47
0
    def test_way02(self):
        """
        Try to pickle and unpickle the result object
        """
        import pickle

        api = overpy.Overpass()
        result = api.parse_json(read_file("json/way-02.json"))
        self._test_way02(result)
        # do pickle and unpickle
        result_string = pickle.dumps(result)
        new_result = pickle.loads(result_string)
        # test new result
        self._test_way02(new_result)
コード例 #48
0
ファイル: test_pep8.py プロジェクト: markstory/lint-review
    def test_execute_fixer__options(self):
        tool = Pep8(self.problems, {
            'fixer': True,
            'max-line-length': 120,
            'exclude': 'W201'
        }, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)

        updated = read_and_restore_file(self.fixtures[1], original)
        assert original != updated, 'File content should change.'
        self.assertEqual(0, len(self.problems.all()),
                         'No errors should be recorded')
コード例 #49
0
    def test_process_files__missing_plugin(self):
        tool = Remarklint(self.problems, {'fixer': True}, root_dir)

        config = 'tests/fixtures/remarklint/.remarkrc'
        original = read_file(config)
        with open(config, 'w') as f:
            f.write('{"plugins": ["unknown-preset"]}')
        tool.process_files([self.fixtures[1]])

        with open(config, 'w') as f:
            f.write(original)
        problems = self.problems.all()
        self.assertEqual(1, len(problems), 'Should have an error')
        self.assertIn('unknown-preset', problems[0].body)
コード例 #50
0
ファイル: test_pep8.py プロジェクト: markstory/lint-review
    def test_execute_fixer__fewer_problems_remain__python3(self):
        options = {'fixer': True, 'python': 3}
        tool = Pep8(self.problems, options, root_dir)

        # The fixture file can have all problems fixed by autopep8
        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        self.assertLessEqual(1, len(self.problems.all()),
                             'Most errors should be fixed')

        text = [c.body for c in self.problems.all()]
        self.assertIn("'<>' is deprecated", ' '.join(text))
コード例 #51
0
    def notestCloneGuestLookup(self):
        """Test using a vm name lookup for cloning"""
        for base in clone_files:
            infile = os.path.join(clonexml_dir, base + "-in.xml")

            vm = None
            try:
                vm = conn.defineXML(tests.read_file(infile))

                cloneobj = CloneDesign(connection=conn)
                cloneobj.original_guest = ORIG_NAME

                cloneobj = self._default_clone_values(cloneobj)
                self._clone_compare(cloneobj, base)
            finally:
                if vm:
                    vm.undefine()
コード例 #52
0
    def notestCloneGuestLookup(self):
        """Test using a vm name lookup for cloning"""
        for base in clone_files:
            infile = os.path.join(clonexml_dir, base + "-in.xml")

            vm = None
            try:
                vm = conn.defineXML(tests.read_file(infile))

                cloneobj = CloneDesign(connection=conn)
                cloneobj.original_guest = ORIG_NAME

                cloneobj = self._default_clone_values(cloneobj)
                self._clone_compare(cloneobj, base)
            finally:
                if vm:
                    vm.undefine()
コード例 #53
0
    def test_overpass_syntax_error_encoding_error(self):
        with pytest.raises(UnicodeDecodeError):
            # File should be encoded with iso8859-15 and will raise an exception
            tmp = read_file("response/bad-request-encoding.html", "rb")
            tmp.decode("utf-8")

        url, t = new_server_thread(HandleOverpassBadRequestEncoding)
        t.start()

        api = overpy.Overpass()
        api.url = url
        with pytest.raises(overpy.exception.OverpassBadRequest):
            # Missing ; after way(1)
            api.query((
                "way(1)"
                "out body;"
            ))
        t.join()
コード例 #54
0
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Relation must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_relation(2046898)

        # Relation must be available
        relation = result1.get_relation(2046898, resolve_missing=True)

        assert isinstance(relation, overpy.Relation)
        assert relation.id == 2046898

        stop_server_thread(server)
コード例 #55
0
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Way must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_way(317146078)

        # Way must be available
        way = result1.get_way(317146078, resolve_missing=True)

        assert isinstance(way, overpy.Way)
        assert way.id == 317146078

        stop_server_thread(server)
コード例 #56
0
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Node must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_area(3605945176)

        # Node must be available
        area = result1.get_area(3605945176, resolve_missing=True)

        assert isinstance(area, overpy.Area)
        assert area.id == 3605945176

        stop_server_thread(server)
コード例 #57
0
    def test_missing_resolvable(self):
        url, server = new_server_thread(HandleResponseJSON02)

        api = overpy.Overpass()
        api.url = url
        result1 = api.parse_json(read_file("json/result-expand-01.json"))

        # Node must not be available
        with pytest.raises(overpy.exception.DataIncomplete):
            result1.get_node(3233854235)

        # Node must be available
        node = result1.get_node(3233854235, resolve_missing=True)

        assert isinstance(node, overpy.Node)
        assert node.id == 3233854235

        stop_server_thread(server)
コード例 #58
0
ファイル: test_puppet.py プロジェクト: markstory/lint-review
    def test_execute_fixer__fixer_ignore(self):
        puppet_config = {
            'fixer': True,
            'fixer_ignore': 'quoted_booleans, variable_is_lowercase',
        }
        tool = Puppet(self.problems, puppet_config, root_dir)

        original = read_file(self.fixtures[1])
        tool.execute_fixer(self.fixtures)
        tool.process_files(self.fixtures)

        read_and_restore_file(self.fixtures[1], original)
        self.assertEqual(2, len(self.problems.all()),
                         'Most errors should be fixed')

        problems = sorted(self.problems.all(), key=attrgetter('line'))
        self.assertIn('ERROR:foo not in autoload module layout',
                      problems[0].body)
        self.assertIn('WARNING:quoted boolean value', problems[1].body)
コード例 #59
0
    def _clone_helper(self, filebase, disks=None, force_list=None,
                      skip_list=None, compare=True):
        """Helper for comparing clone input/output from 2 xml files"""
        infile = os.path.join(clonexml_dir, filebase + "-in.xml")
        in_content = tests.read_file(infile)

        cloneobj = CloneDesign(connection=conn)
        cloneobj.original_xml = in_content
        for force in force_list or []:
            cloneobj.force_target = force
        for skip in skip_list or []:
            cloneobj.skip_target = skip

        cloneobj = self._default_clone_values(cloneobj, disks)

        if compare:
            self._clone_compare(cloneobj, filebase)
            self._clone_define(filebase)
        else:
            cloneobj.setup()
コード例 #60
0
ファイル: test_eslint.py プロジェクト: markstory/lint-review
    def test_execute_fixer__install_plugins(self):
        custom_dir = root_dir + '/tests/fixtures/eslint_custom'
        tool = Eslint(self.problems, {
            'config': 'config.json',
            'install_plugins': True,
            'fixer': True
        }, custom_dir)

        target = 'tests/fixtures/eslint_custom/fixer_errors.js'

        # The fixture file can have all problems fixed by eslint
        original = read_file(target)
        tool.execute_fixer(['fixer_errors.js'])
        tool.process_files(['fixer_errors.js'])

        read_and_restore_file(target, original)
        self.assertEqual(0, len(self.problems.all()),
                         'All errors should be autofixed')
        for image in docker.images():
            self.assertNotIn('eslint-', image, 'no eslint image remains')