def test_two_formatter_no_overlap(self):
     b = StringFormatter("one {arg} ", arg="hi") + StringFormatter(
         "a {different} arg", different="diff")
     self.assertEqual("one {arg} a {different} arg", b._format)
     self.assertEqual(2, len(b.kwargs))
     self.assertEqual("hi", b.kwargs["arg"])
     self.assertEqual("diff", b.kwargs["different"])
 def test_evaluate_from_input_selector_resolved(self):
     namesel = InputSelector("name")
     adjsel = InputSelector("adjsel")
     b = StringFormatter("{name} is {adjective}",
                         name=namesel,
                         adjective=adjsel)
     inp = {"name": "Janis", "adjsel": "pretty good"}
     self.assertEqual("Janis is pretty good", b.evaluate(inp))
    def test_multi_string_formatter(self):
        sf = StringFormatter("iteration_{i}", i=InputSelector("iters"))
        sfs = sf.evaluate({"iters": [1, 2, 3]})

        self.assertEqual(3, len(sfs))
        self.assertEqual("iteration_1", sfs[0])
        self.assertEqual("iteration_2", sfs[1])
        self.assertEqual("iteration_3", sfs[2])
 def test_two_formatters_nonequal_overlap(self):
     try:
         b = StringFormatter("one {arg} ", arg="hi") + StringFormatter(
             "and the same {arg}", arg="hi2")
         self.fail(
             "Test 'test_two_formatters_nonequal_overlap' should fail as the two args have different values"
         )
     except ConflictingArgumentsException:
         self.assertTrue(True)
    def test_dotproduct_string_formatter(self):
        sf = StringFormatter("iteration_{i}_{j}",
                             i=InputSelector("it1"),
                             j=InputSelector("it2"))
        sfs = sf.evaluate({"it1": [1, 2, 3], "it2": ["a", "b", "c"]})

        self.assertEqual(3, len(sfs))
        self.assertEqual("iteration_1_a", sfs[0])
        self.assertEqual("iteration_2_b", sfs[1])
        self.assertEqual("iteration_3_c", sfs[2])
示例#6
0
    def to_string_formatter(self):
        import re
        from janis_core.operators.stringformatter import StringFormatter

        key = re.sub(r"\W+", "", str(self))
        kwarg = {key: self}
        return StringFormatter(f"{{{key}}}", **kwarg)
    def test_byproduct_by_concat_string(self):
        try:
            b = StringFormatter("one {") + "test}"
            self.fail(
                "Test 'test_byproduct_by_concat_string' should fail as concatting the string creates a new placeholder"
            )

        except InvalidByProductException:
            self.assertTrue(True)
 def test_double(self):
     d = {"a": [1, 2], "b": ["a", "b", "c"]}
     combinations = StringFormatter.generate_combinations_of_input_dicts(
         list(d.items()))
     self.assertEqual(6, len(combinations))
     self.assertDictEqual({"a": 1, "b": "a"}, combinations[0])
     self.assertDictEqual({"a": 1, "b": "b"}, combinations[1])
     self.assertDictEqual({"a": 1, "b": "c"}, combinations[2])
     self.assertDictEqual({"a": 2, "b": "a"}, combinations[3])
     self.assertDictEqual({"a": 2, "b": "b"}, combinations[4])
     self.assertDictEqual({"a": 2, "b": "c"}, combinations[5])
示例#9
0
    def to_string_formatter(self):
        from janis_core.operators.stringformatter import StringFormatter

        return StringFormatter("{inp}", inp=self)
示例#10
0
 def test_formatter_duplicate_replacement(self):
     b = StringFormatter("{arg} is the same as {arg}", arg=None)
     resolved = b.resolve_with_resolved_values(
         arg="S07E25")  # ;) https://www.youtube.com/watch?v=7WCfTREZSdQ
     self.assertEqual("S07E25 is the same as S07E25", resolved)
示例#11
0
 def test_formatter_two_replacement(self):
     b = StringFormatter("{howmany} argument(s) {wasORwere} resolved",
                         howmany=None,
                         wasORwere=None)
     resolved = b.resolve_with_resolved_values(howmany=1, wasORwere="was")
     self.assertEqual("1 argument(s) was resolved", resolved)
示例#12
0
 def test_formatter_one_replacement(self):
     b = StringFormatter("one {arg} was resolved", arg=None)
     resolved = b.resolve_with_resolved_values(arg="value")
     self.assertEqual("one value was resolved", resolved)
示例#13
0
 def test_formatter_no_replacement(self):
     b = StringFormatter("no args")
     resolved = b.resolve_with_resolved_values()
     self.assertEqual("no args", resolved)
示例#14
0
 def test_one_correct_argument(self):
     b = StringFormatter("this {test} has one argument",
                         test="My test _format")
     self.assertDictEqual({"test": "My test _format"}, b.kwargs)
示例#15
0
 def test_byproduct_by_concat_string_covered(self):
     b = StringFormatter("one {arg} + another {", arg="q") + "arg}"
     self.assertEqual("one {arg} + another {arg}", b._format)
     self.assertEqual(1, len(b.kwargs))
示例#16
0
    def to_string_formatter(self):
        from janis_core.operators.stringformatter import StringFormatter

        key = self.node.id() + "_" + self.tag
        kwarg = {key: self}
        return StringFormatter(f"{{{key}}}", **kwarg)
示例#17
0
 def test_two_formatters_equal_overlap(self):
     b = StringFormatter("one {arg} ", arg="hi") + StringFormatter(
         "and the same {arg}", arg="hi")
     self.assertEqual("one {arg} and the same {arg}", b._format)
     self.assertEqual(1, len(b.kwargs))
     self.assertEqual("hi", b.kwargs["arg"])
示例#18
0
 def test_two_formatters_no_format(self):
     b = StringFormatter("no args") + StringFormatter(" in this")
     self.assertEqual("no args in this", b._format)
     self.assertEqual(0, len(b.kwargs))
示例#19
0
 def test_formatter_and_string(self):
     b = StringFormatter("no args") + " here"
     self.assertEqual("no args here", b._format)
     self.assertEqual(0, len(b.kwargs))
示例#20
0
    def to_string_formatter(self):
        from janis_core.operators.stringformatter import StringFormatter

        return StringFormatter("{value}", value=self.inner_selector)
示例#21
0
 def test_reverse_add(self):
     b = "Hello, " + StringFormatter("world")
     self.assertEqual("Hello, world", b._format)
示例#22
0
    def to_string_formatter(self):
        kwarg = {self.input_to_select: self}
        from janis_core.operators.stringformatter import StringFormatter

        return StringFormatter(f"{{{self.input_to_select}}}", **kwarg)
示例#23
0
 def test_no_format(self):
     b = StringFormatter("this _format has no arguments")
     self.assertDictEqual({}, b.kwargs)