Beispiel #1
0
 def test_can_add_analyzer_for_filetype(self):
     conf = Configuration()
     analyzer = Analyzer()
     conf.add_analyzer_for_file_type(analyzer, 'javascript')
     resource = Resource('file.js')
     analyzers = conf.get_analyzers_for_resource(resource)
     self.assertListEqual([analyzer], analyzers)
Beispiel #2
0
 def test_returns_non_when_asking_for_analyzers_for_an_unknown_file_type(self):
     conf = Configuration()
     analyzer = Analyzer()
     conf.add_analyzer_for_file_type(analyzer, 'javascript')
     resource = Resource('file.foo')
     analyzers = conf.get_analyzers_for_resource(resource)
     self.assertIsNone(analyzers)
Beispiel #3
0
    def test_add_analyzer_checks_classes(self):
        conf = Configuration()
        self.assertRaises(Exception, conf.add_analyzer_for_file_type, 'string instead of an analyzer', 'javascript')

        # should not throw
        conf.add_analyzer_for_file_type(Analyzer(), 'javascript')
        # should not throw
        conf.add_analyzer_for_file_type(SizeAnalyzer(), 'javascript')
Beispiel #4
0
    def test_add_minifier_checks_classes(self):
        conf = Configuration()
        self.assertRaises(Exception, conf.set_minifier_for_file_type, 'string instead of an minifier', 'javascript')

        # should not throw
        conf.set_minifier_for_file_type(Minifier(), 'javascript')
        # should not throw
        conf.set_minifier_for_file_type(YUICompressorMinifier(), 'javascript')
Beispiel #5
0
 def test_get_analyzers_for_resource_with_skip_list(self):
     lib_resource = Resource(os.path.join(os.getcwd(), 'lib', 'jquery.js'))
     src_resource = Resource(os.path.join(os.getcwd(), 'src', 'file.js'))
     conf = Configuration()
     analyzer = Analyzer()
     conf.add_analyzer_for_file_type(analyzer, 'javascript', ['lib/*'])
     self.assertIsNone(conf.get_analyzers_for_resource(lib_resource))
     self.assertEqual([analyzer], conf.get_analyzers_for_resource(src_resource))
Beispiel #6
0
 def test_can_load_minfiers_from_config_file(self):
     config_file_path = os.path.join(self.test_env_dir, 'blend.config')
     create_file_with_content(config_file_path,
         """{
             "minifiers": {
                 "javascript": {
                     "name": "blend.YUICompressorMinifier"
                 }
             }
         }""")
     conf = Configuration(config_file_path)
     resource = Resource('file.js')
     actual_minifier = conf.get_minifier_for_file_type(resource.file_type)
     self.assertIsNotNone(actual_minifier)
     self.assertIsInstance(actual_minifier, YUICompressorMinifier)
Beispiel #7
0
    def test_can_load_analyzers_from_config_file(self):
        config_file_path = os.path.join(self.test_env_dir, 'blend.config')
        create_file_with_content(config_file_path,
"""{
    "analyzers": {
        "javascript": [
            {
                "name": "blend.SizeAnalyzer",
                "skip_list": [
                    "bin"
                ]
            }
        ]
    }
}""")
        conf = Configuration(config_file_path)
        resource = Resource('file.js')
        actual_analyzers = conf.get_analyzers_for_resource(resource)
        self.assertIsNotNone(actual_analyzers)
        self.assertEqual(1, len(actual_analyzers))
        self.assertIsInstance(actual_analyzers[0], SizeAnalyzer)
        self.assertIsNotNone(conf.analyzer_skip_lists)
Beispiel #8
0
 def test_get_analyzers_for_resource_with_skip_list(self):
     lib_resource = Resource(os.path.join(os.getcwd(), 'lib', 'jquery.js'))
     src_resource = Resource(os.path.join(os.getcwd(), 'src', 'file.js'))
     conf = Configuration()
     analyzer = Analyzer()
     conf.add_analyzer_for_file_type(analyzer, 'javascript', ['lib/*'])
     self.assertIsNone(conf.get_analyzers_for_resource(lib_resource))
     self.assertEqual([analyzer],
                      conf.get_analyzers_for_resource(src_resource))
Beispiel #9
0
    def test_add_minifier_checks_classes(self):
        conf = Configuration()
        self.assertRaises(Exception, conf.set_minifier_for_file_type,
                          'string instead of an minifier', 'javascript')

        # should not throw
        conf.set_minifier_for_file_type(Minifier(), 'javascript')
        # should not throw
        conf.set_minifier_for_file_type(YUICompressorMinifier(), 'javascript')
Beispiel #10
0
    def test_add_analyzer_checks_classes(self):
        conf = Configuration()
        self.assertRaises(Exception, conf.add_analyzer_for_file_type,
                          'string instead of an analyzer', 'javascript')

        # should not throw
        conf.add_analyzer_for_file_type(Analyzer(), 'javascript')
        # should not throw
        conf.add_analyzer_for_file_type(SizeAnalyzer(), 'javascript')
Beispiel #11
0
 def test_add_analyzer_for_file_type_raises_when_skip_list_is_a_string(
         self):
     conf = Configuration()
     self.assertRaises(Exception, conf.add_analyzer_for_file_type,
                       Analyzer(), 'javascript', 'something invalid')
Beispiel #12
0
 def test_can_add_minifier_for_filetype(self):
     conf = Configuration()
     minifier = Minifier()
     conf.set_minifier_for_file_type(minifier, 'javascript')
     actual_minifier = conf.get_minifier_for_file_type('javascript')
     self.assertEqual(minifier, actual_minifier)
Beispiel #13
0
 def test_returns_none_when_asking_for_minifier_for_an_unknown_file_type(self):
     conf = Configuration()
     minifier = Minifier()
     conf.set_minifier_for_file_type(minifier, 'javascript')
     analyzers = conf.get_minifier_for_file_type('some-other-type')
     self.assertIsNone(analyzers)
Beispiel #14
0
 def test_can_add_minifier_for_filetype(self):
     conf = Configuration()
     minifier = Minifier()
     conf.set_minifier_for_file_type(minifier, 'javascript')
     actual_minifier = conf.get_minifier_for_file_type('javascript')
     self.assertEqual(minifier, actual_minifier)