How to use lesscpy - 10 common examples

To help you get started, we’ve selected a few lesscpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lesscpy / lesscpy / lesscpy / plib / call.py View on Github external
def isurl(self, string, *args):
        """Is url
        args:
            string (str): match
        returns:
            bool
        """
        arg = utility.destring(string)
        regex = re.compile(
            r'^(?:http|ftp)s?://'  # http:// or https://
            r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+'
            r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'  # domain...
            # localhost...
            r'localhost|'
            r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'  # ...or ip
            # optional port
            r'(?::\d+)?'
            r'(?:/?|[/?]\S+)$',
            re.IGNORECASE)
        return regex.match(arg)
github lesscpy / lesscpy / test / test_utility.py View on Github external
def test_is_color(self):
        test = utility.is_color
        self.assertTrue(test('#123'))
        self.assertTrue(test('#123456'))
        self.assertTrue(test('#Df3'))
        self.assertTrue(test('#AbCdEf'))
        self.assertFalse(test('#AbCdEg'))
        self.assertFalse(test('#h12345'))
        self.assertFalse(test('#12345'))
        self.assertFalse(test('AbCdEf'))
        self.assertFalse(test(''))
        self.assertFalse(test('.925'))
        self.assertFalse(test(False))
        self.assertFalse(test([]))
github lesscpy / lesscpy / test / core.py View on Github external
def do_case_expected(self):
        lessf, cssf, minf = args
        if os.path.exists(cssf):
            p = parser.LessParser()
            p.parse(filename=lessf)
            f = formatter.Formatter(Opt())
            pout = f.format(p).split('\n')
            pl = len(pout)
            i = 0
            with open(cssf) as cssf:
                for line in cssf.readlines():
                    if i >= pl:
                        self.fail("%s: result has less lines (%d < %d)" %
                                  (cssf, i, pl))
                    line = line.rstrip()
                    if not line:
                        continue
                    self.assertEqual(line, pout[i],
                                     '%s: Line %d' % (cssf, i + 1))
                    i += 1
github lesscpy / lesscpy / test / test_utility.py View on Github external
def test_is_variable(self):
        test = utility.is_variable
        self.assertTrue(test('@var'))
        self.assertTrue(test('-@var'))
        self.assertFalse(test('var'))
        self.assertFalse(test(''))
        self.assertFalse(test(False))
        self.assertFalse(test([]))
github lesscpy / lesscpy / test / core.py View on Github external
continue
                    self.assertEqual(line, pout[i],
                                     '%s: Line %d' % (cssf, i + 1))
                    i += 1
            if pl > i and i:
                self.fail(
                    "%s: result has more lines (%d > %d)" % (cssf, i, pl))
        else:
            self.fail("%s not found..." % cssf)
        if minf:
            if os.path.exists(minf):
                p = parser.LessParser()
                opt = Opt()
                opt.minify = True
                p.parse(filename=lessf)
                f = formatter.Formatter(opt)
                mout = f.format(p).split('\n')
                ml = len(mout)
                i = 0
                with open(minf) as cssf:
                    for line in cssf.readlines():
                        if i >= ml:
                            self.fail("%s: result has less lines (%d < %d)" %
                                      (minf, i, ml))
                        self.assertEqual(line.rstrip(), mout[i],
                                         '%s: Line %d' % (minf, i + 1))
                        i += 1
                if ml > i and i:
                    self.fail(
                        "%s: result has more lines (%d > %d)" % (minf, i, ml))
            else:
                self.fail("%s not found..." % minf)
github lesscpy / lesscpy / test / core.py View on Github external
def do_case_expected(self):
        lessf, cssf, minf = args
        if os.path.exists(cssf):
            p = parser.LessParser()
            p.parse(filename=lessf)
            f = formatter.Formatter(Opt())
            pout = f.format(p).split('\n')
            pl = len(pout)
            i = 0
            with open(cssf) as cssf:
                for line in cssf.readlines():
                    if i >= pl:
                        self.fail("%s: result has less lines (%d < %d)" %
                                  (cssf, i, pl))
                    line = line.rstrip()
                    if not line:
                        continue
                    self.assertEqual(line, pout[i],
                                     '%s: Line %d' % (cssf, i + 1))
                    i += 1
            if pl > i and i:
                self.fail(
github lesscpy / lesscpy / test / test_utility.py View on Github external
def test_analyze(self):
        test = utility.analyze_number
        self.assertEqual((0, ''), test('0'))
        self.assertEqual((1, ''), test('1'))
        self.assertEqual(type(test('1')[0]), int)
        self.assertEqual(type(test('-1')[0]), int)
        self.assertEqual((1.0, ''), test('1.0'))
        self.assertEqual(type(test('-1.0')[0]), float)
        self.assertEqual((0, 'px'), test('0px'))
        self.assertEqual((1, 'px'), test('1px'))
        self.assertEqual((1.0, 'px'), test('1.0px'))
        self.assertEqual((0, 'px'), test('-0px'))
        self.assertEqual((-1, 'px'), test('-1px'))
        self.assertEqual(type(test('-1px')[0]), int)
        self.assertEqual((-1.0, 'px'), test('-1.0px'))
        self.assertEqual(type(test('-1.0px')[0]), float)
        self.assertRaises(SyntaxError, test, 'gg')
        self.assertRaises(SyntaxError, test, '-o')
github lesscpy / lesscpy / test / test_utility.py View on Github external
def test_with_unit(self):
        test = utility.with_unit
        self.assertEqual('1px', test((1, 'px')))
        self.assertEqual('1px', test(1, 'px'))
        self.assertEqual('1.0px', test(1.0, 'px'))
        self.assertEqual('0.0px', test('.0', 'px'))
        self.assertEqual('0.6px', test(.6, 'px'))
        self.assertEqual('1', test(1))
        self.assertEqual('1', test(1, None))
        self.assertEqual('1', test(1, ))
github lesscpy / lesscpy / test / test_utility.py View on Github external
def test_convergent_round(self):
        test = utility.convergent_round
        self.assertEqual(-4, test(-4.5))
        self.assertEqual(-4, test(-3.5))
        self.assertEqual(-2, test(-2.5))
        self.assertEqual(-2, test(-1.5))
        self.assertEqual(0, test(-0.5))
        self.assertEqual(0, test(0.5))
        self.assertEqual(2, test(1.5))
        self.assertEqual(2, test(2.5))
        self.assertEqual(3.0, test(10.0 / 3, 0))
        self.assertEqual(4, test(3.5))
        self.assertEqual(4, test(4.5))
github lesscpy / lesscpy / test / core.py View on Github external
self.fail("%s: result has less lines (%d < %d)" %
                                  (cssf, i, pl))
                    line = line.rstrip()
                    if not line:
                        continue
                    self.assertEqual(line, pout[i],
                                     '%s: Line %d' % (cssf, i + 1))
                    i += 1
            if pl > i and i:
                self.fail(
                    "%s: result has more lines (%d > %d)" % (cssf, i, pl))
        else:
            self.fail("%s not found..." % cssf)
        if minf:
            if os.path.exists(minf):
                p = parser.LessParser()
                opt = Opt()
                opt.minify = True
                p.parse(filename=lessf)
                f = formatter.Formatter(opt)
                mout = f.format(p).split('\n')
                ml = len(mout)
                i = 0
                with open(minf) as cssf:
                    for line in cssf.readlines():
                        if i >= ml:
                            self.fail("%s: result has less lines (%d < %d)" %
                                      (minf, i, ml))
                        self.assertEqual(line.rstrip(), mout[i],
                                         '%s: Line %d' % (minf, i + 1))
                        i += 1
                if ml > i and i: